Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(167)

Side by Side Diff: third_party/prediction/suggest/policyimpl/dictionary/utils/mmapped_buffer.h

Issue 1247903003: Add spellcheck and word suggestion to the prediction service (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2013, The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #ifndef LATINIME_MMAPPED_BUFFER_H
18 #define LATINIME_MMAPPED_BUFFER_H
19
20 #include <cstdint>
21 #include <memory>
22
23 #include "third_party/prediction/defines.h"
24 #include "third_party/prediction/utils/byte_array_view.h"
25
26 namespace latinime {
27
28 class MmappedBuffer {
29 public:
30 typedef std::unique_ptr<const MmappedBuffer> MmappedBufferPtr;
31
32 static MmappedBufferPtr openBuffer(const char* const path,
33 const int bufferOffset,
34 const int bufferSize,
35 const bool isUpdatable);
36
37 // Mmap entire file.
38 static MmappedBufferPtr openBuffer(const char* const path,
39 const bool isUpdatable);
40
41 static MmappedBufferPtr openBuffer(const char* const dirPath,
42 const char* const fileName,
43 const bool isUpdatable);
44
45 ~MmappedBuffer();
46
47 ReadWriteByteArrayView getReadWriteByteArrayView() const {
48 return mByteArrayView;
49 }
50
51 ReadOnlyByteArrayView getReadOnlyByteArrayView() const {
52 return mByteArrayView.getReadOnlyView();
53 }
54
55 AK_FORCE_INLINE bool isUpdatable() const { return mIsUpdatable; }
56
57 private:
58 AK_FORCE_INLINE MmappedBuffer(uint8_t* const buffer,
59 const int bufferSize,
60 void* const mmappedBuffer,
61 const int alignedSize,
62 const int mmapFd,
63 const bool isUpdatable)
64 : mByteArrayView(buffer, bufferSize),
65 mMmappedBuffer(mmappedBuffer),
66 mAlignedSize(alignedSize),
67 mMmapFd(mmapFd),
68 mIsUpdatable(isUpdatable) {}
69
70 // Empty file. We have to handle an empty file as a valid part of a
71 // dictionary.
72 AK_FORCE_INLINE MmappedBuffer(const bool isUpdatable)
73 : mByteArrayView(),
74 mMmappedBuffer(nullptr),
75 mAlignedSize(0),
76 mMmapFd(0),
77 mIsUpdatable(isUpdatable) {}
78
79 DISALLOW_IMPLICIT_CONSTRUCTORS(MmappedBuffer);
80
81 const ReadWriteByteArrayView mByteArrayView;
82 void* const mMmappedBuffer;
83 const int mAlignedSize;
84 const int mMmapFd;
85 const bool mIsUpdatable;
86 };
87 }
88 #endif /* LATINIME_MMAPPED_BUFFER_H */
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698