blob: 3a4ffce1aadddd716fe7818126c5966809ee716a [file] [log] [blame]
Yao Chend5aa01b32017-12-19 16:46:36 -08001/*
2 * Copyright (C) 2017 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#pragma once
18
19#include <utils/JenkinsHash.h>
20#include "frameworks/base/cmds/statsd/src/stats_log.pb.h"
21
22namespace android {
23namespace os {
24namespace statsd {
25
26class HashableDimensionKey {
27public:
Yangster-mac20877162017-12-22 17:19:39 -080028 explicit HashableDimensionKey(const DimensionsValue& dimensionsValue)
29 : mDimensionsValue(dimensionsValue){};
Yao Chend5aa01b32017-12-19 16:46:36 -080030
31 HashableDimensionKey(){};
32
33 HashableDimensionKey(const HashableDimensionKey& that)
Yangster-mac20877162017-12-22 17:19:39 -080034 : mDimensionsValue(that.getDimensionsValue()){};
Yao Chend5aa01b32017-12-19 16:46:36 -080035
36 HashableDimensionKey& operator=(const HashableDimensionKey& from) = default;
37
38 std::string toString() const;
39
Yangster-mac20877162017-12-22 17:19:39 -080040 inline const DimensionsValue& getDimensionsValue() const {
41 return mDimensionsValue;
Yao Chend5aa01b32017-12-19 16:46:36 -080042 }
43
44 bool operator==(const HashableDimensionKey& that) const;
45
46 bool operator<(const HashableDimensionKey& that) const;
47
48 inline const char* c_str() const {
49 return toString().c_str();
50 }
51
52private:
Yangster-mac20877162017-12-22 17:19:39 -080053 DimensionsValue mDimensionsValue;
Yao Chend5aa01b32017-12-19 16:46:36 -080054};
55
Yangster-mac20877162017-12-22 17:19:39 -080056android::hash_t hashDimensionsValue(const DimensionsValue& value);
57
Yao Chend5aa01b32017-12-19 16:46:36 -080058} // namespace statsd
59} // namespace os
60} // namespace android
61
62namespace std {
63
64using android::os::statsd::HashableDimensionKey;
Yao Chend5aa01b32017-12-19 16:46:36 -080065
66template <>
67struct hash<HashableDimensionKey> {
68 std::size_t operator()(const HashableDimensionKey& key) const {
Yangster-mac20877162017-12-22 17:19:39 -080069 return hashDimensionsValue(key.getDimensionsValue());
Yao Chend5aa01b32017-12-19 16:46:36 -080070 }
71};
72
73} // namespace std