Dmitri Plotnikov | 5effd85 | 2021-08-11 14:55:58 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2021 The Android Open Source Project |
| 3 | * Android BPF library - public API |
| 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | #pragma once |
| 19 | |
| 20 | #include <vector> |
| 21 | #include "MultiStateCounter.h" |
| 22 | |
| 23 | namespace android { |
| 24 | namespace battery { |
| 25 | |
Dmitri Plotnikov | 0a6dc40 | 2024-01-19 14:33:20 -0800 | [diff] [blame] | 26 | /** |
| 27 | * Wrapper for an array of uint64's. |
| 28 | */ |
| 29 | class Uint64Array { |
| 30 | protected: |
| 31 | size_t mSize; |
| 32 | |
| 33 | public: |
| 34 | Uint64Array() : Uint64Array(0) {} |
| 35 | |
| 36 | Uint64Array(size_t size) : mSize(size) {} |
| 37 | |
| 38 | virtual ~Uint64Array() {} |
| 39 | |
| 40 | size_t size() const { return mSize; } |
| 41 | |
| 42 | /** |
| 43 | * Returns the wrapped array. |
| 44 | * |
| 45 | * Nullable! Null should be interpreted the same as an array of zeros |
| 46 | */ |
| 47 | virtual const uint64_t *data() const { return nullptr; } |
| 48 | |
| 49 | friend std::ostream &operator<<(std::ostream &os, const Uint64Array &v); |
| 50 | |
| 51 | // Test API |
| 52 | bool operator==(const Uint64Array &other) const; |
| 53 | }; |
| 54 | |
| 55 | /** |
| 56 | * Mutable version of Uint64Array. |
| 57 | */ |
| 58 | class Uint64ArrayRW: public Uint64Array { |
| 59 | uint64_t* mData; |
| 60 | |
| 61 | public: |
| 62 | Uint64ArrayRW() : Uint64ArrayRW(0) {} |
| 63 | |
| 64 | Uint64ArrayRW(size_t size) : Uint64Array(size), mData(nullptr) {} |
| 65 | |
| 66 | Uint64ArrayRW(const Uint64Array ©); |
| 67 | |
| 68 | // Need an explicit copy constructor. In the initialization context C++ does not understand that |
| 69 | // a Uint64ArrayRW is a Uint64Array. |
| 70 | Uint64ArrayRW(const Uint64ArrayRW ©) : Uint64ArrayRW((const Uint64Array &) copy) {} |
| 71 | |
| 72 | // Test API |
| 73 | Uint64ArrayRW(std::initializer_list<uint64_t> init); |
| 74 | |
| 75 | ~Uint64ArrayRW() override { delete[] mData; } |
| 76 | |
| 77 | const uint64_t *data() const override { return mData; } |
| 78 | |
| 79 | // NonNull. Will initialize the wrapped array if it is null. |
| 80 | uint64_t *dataRW(); |
| 81 | |
| 82 | Uint64ArrayRW &operator=(const Uint64Array &t); |
| 83 | }; |
| 84 | |
| 85 | typedef MultiStateCounter<Uint64ArrayRW, Uint64Array> LongArrayMultiStateCounter; |
Dmitri Plotnikov | 5effd85 | 2021-08-11 14:55:58 -0700 | [diff] [blame] | 86 | |
| 87 | } // namespace battery |
| 88 | } // namespace android |