blob: 6b3057d2408028531db8b5ad01657b90301144e2 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 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 ANDROID_TOKENIZER_H
18#define ANDROID_TOKENIZER_H
19
20#include <utils/Vector.h>
21#include <utils/Errors.h>
22
23// ----------------------------------------------------------------------------
24
25namespace android {
26
27class Tokenizer
28{
29public:
30 Tokenizer();
31 Tokenizer(const Tokenizer& other);
32 ~Tokenizer();
33
34 uint32_t acquire();
35 status_t reserve(uint32_t token);
36 status_t release(uint32_t token);
37 bool isAcquired(uint32_t token) const;
38
39 void dump() const;
40
41 struct run_t {
42 run_t() {};
43 run_t(uint32_t f, uint32_t l) : first(f), length(l) {}
44 uint32_t first;
45 uint32_t length;
46 };
47private:
48 ssize_t _indexOrderOf(uint32_t token, size_t* order=0) const;
49 ssize_t _insertTokenAt(uint32_t token, size_t index);
50 Vector<run_t> mRanges;
51};
52
53}; // namespace android
54
55// ----------------------------------------------------------------------------
56
57#endif // ANDROID_TOKENIZER_H