2
* Copyright (C) 2010 The Android Open Source Project
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
8
* http://www.apache.org/licenses/LICENSE-2.0
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.
17
#ifndef _UTILS_PROPERTY_MAP_H
18
#define _UTILS_PROPERTY_MAP_H
20
#include <utils/KeyedVector.h>
21
#include <utils/String8.h>
22
#include <utils/Errors.h>
23
#include <utils/Tokenizer.h>
28
* Provides a mechanism for passing around string-based property key / value pairs
29
* and loading them from property files.
31
* The property files have the following simple structure:
36
* Keys and values are any sequence of printable ASCII characters.
37
* The '=' separates the key from the value.
38
* The key and value may not contain whitespace.
40
* The '\' character is reserved for escape sequences and is not currently supported.
41
* The '"" character is reserved for quoting and is not currently supported.
42
* Files that contain the '\' or '"' character will fail to parse.
44
* The file must not contain duplicate keys.
46
* TODO Support escape sequences and quoted values when needed.
50
/* Creates an empty property map. */
54
/* Clears the property map. */
58
* Replaces the property with the same key if it is already present.
60
void addProperty(const String8& key, const String8& value);
62
/* Returns true if the property map contains the specified key. */
63
bool hasProperty(const String8& key) const;
65
/* Gets the value of a property and parses it.
66
* Returns true and sets outValue if the key was found and its value was parsed successfully.
67
* Otherwise returns false and does not modify outValue. (Also logs a warning.)
69
bool tryGetProperty(const String8& key, String8& outValue) const;
70
bool tryGetProperty(const String8& key, bool& outValue) const;
71
bool tryGetProperty(const String8& key, int32_t& outValue) const;
72
bool tryGetProperty(const String8& key, float& outValue) const;
74
/* Adds all values from the specified property map. */
75
void addAll(const PropertyMap* map);
77
/* Gets the underlying property map. */
78
inline const KeyedVector<String8, String8>& getProperties() const { return mProperties; }
80
/* Loads a property map from a file. */
81
static status_t load(const String8& filename, PropertyMap** outMap);
86
Tokenizer* mTokenizer;
89
Parser(PropertyMap* map, Tokenizer* tokenizer);
96
status_t parseKeyProperty();
97
status_t parseModifier(const String8& token, int32_t* outMetaState);
98
status_t parseCharacterLiteral(char16_t* outCharacter);
101
KeyedVector<String8, String8> mProperties;
104
} // namespace android
106
#endif // _UTILS_PROPERTY_MAP_H