Primiano Tucci | 4e01f63 | 2020-06-11 17:03:05 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2020 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 INCLUDE_PERFETTO_TRACE_PROCESSOR_ITERATOR_H_ |
| 18 | #define INCLUDE_PERFETTO_TRACE_PROCESSOR_ITERATOR_H_ |
| 19 | |
| 20 | #include <stdint.h> |
| 21 | |
| 22 | #include <memory> |
| 23 | |
| 24 | #include "perfetto/base/export.h" |
| 25 | #include "perfetto/trace_processor/basic_types.h" |
| 26 | #include "perfetto/trace_processor/status.h" |
| 27 | |
| 28 | namespace perfetto { |
| 29 | namespace trace_processor { |
| 30 | |
| 31 | class IteratorImpl; |
| 32 | |
| 33 | // Iterator returning SQL rows satisfied by a query. |
| 34 | class PERFETTO_EXPORT Iterator { |
| 35 | public: |
| 36 | explicit Iterator(std::unique_ptr<IteratorImpl>); |
| 37 | ~Iterator(); |
| 38 | |
| 39 | Iterator(Iterator&) noexcept = delete; |
| 40 | Iterator& operator=(Iterator&) = delete; |
| 41 | |
| 42 | Iterator(Iterator&&) noexcept; |
| 43 | Iterator& operator=(Iterator&&); |
| 44 | |
| 45 | // Forwards the iterator to the next result row and returns a boolean of |
| 46 | // whether there is a next row. If this method returns false, |
| 47 | // |Status()| should be called to check if there was an error. If |
| 48 | // there was no error, this means the EOF was reached. |
| 49 | bool Next(); |
| 50 | |
| 51 | // Returns the value associated with the column |col|. Any call to |
| 52 | // |Get()| must be preceded by a call to |Next()| returning |
Lalit Maganti | 0b81007 | 2020-07-08 12:00:45 +0100 | [diff] [blame] | 53 | // true. |col| must be less than the number returned by |ColumnCount()|. |
Primiano Tucci | 4e01f63 | 2020-06-11 17:03:05 +0100 | [diff] [blame] | 54 | SqlValue Get(uint32_t col); |
| 55 | |
| 56 | // Returns the name of the column at index |col|. Can be called even before |
| 57 | // calling |Next()|. |
| 58 | std::string GetColumnName(uint32_t col); |
| 59 | |
| 60 | // Returns the number of columns in this iterator's query. Can be called |
| 61 | // even before calling |Next()|. |
| 62 | uint32_t ColumnCount(); |
| 63 | |
| 64 | // Returns the status of the iterator. |
| 65 | util::Status Status(); |
| 66 | |
| 67 | private: |
Primiano Tucci | 4079d1d | 2020-06-30 11:03:38 +0100 | [diff] [blame] | 68 | friend class QueryResultSerializer; |
| 69 | |
| 70 | // This is to allow QueryResultSerializer, which is very perf sensitive, to |
| 71 | // access direct the impl_ and avoid one extra function call for each cell. |
| 72 | template <typename T = IteratorImpl> |
| 73 | std::unique_ptr<T> take_impl() { |
| 74 | return std::move(iterator_); |
| 75 | } |
| 76 | |
Primiano Tucci | 4e01f63 | 2020-06-11 17:03:05 +0100 | [diff] [blame] | 77 | // A PIMPL pattern is used to avoid leaking the dependencies on sqlite3.h and |
| 78 | // other internal classes. |
| 79 | std::unique_ptr<IteratorImpl> iterator_; |
| 80 | }; |
| 81 | |
| 82 | } // namespace trace_processor |
| 83 | } // namespace perfetto |
| 84 | |
| 85 | #endif // INCLUDE_PERFETTO_TRACE_PROCESSOR_ITERATOR_H_ |