xref: /aosp_15_r20/external/perfetto/src/trace_processor/sqlite/bindings/sqlite_value.h (revision 6dbdd20afdafa5e3ca9b8809fa73465d530080dc)
1 /*
2  * Copyright (C) 2024 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 SRC_TRACE_PROCESSOR_SQLITE_BINDINGS_SQLITE_VALUE_H_
18 #define SRC_TRACE_PROCESSOR_SQLITE_BINDINGS_SQLITE_VALUE_H_
19 
20 #include <sqlite3.h>  // IWYU pragma: export
21 #include <cstdint>
22 
23 #include "src/trace_processor/sqlite/bindings/sqlite_type.h"
24 
25 namespace perfetto::trace_processor::sqlite::value {
26 
27 // This file contains wraps the sqlite3_value_* functions which extract values
28 // from sqlite3_value structs.
29 
Type(sqlite3_value * value)30 inline Type Type(sqlite3_value* value) {
31   return static_cast<enum Type>(sqlite3_value_type(value));
32 }
33 
IsNull(sqlite3_value * value)34 inline bool IsNull(sqlite3_value* value) {
35   return Type(value) == Type::kNull;
36 }
37 
Int64(sqlite3_value * value)38 inline int64_t Int64(sqlite3_value* value) {
39   return sqlite3_value_int64(value);
40 }
41 
Double(sqlite3_value * value)42 inline double Double(sqlite3_value* value) {
43   return sqlite3_value_double(value);
44 }
45 
Text(sqlite3_value * value)46 inline const char* Text(sqlite3_value* value) {
47   return reinterpret_cast<const char*>(sqlite3_value_text(value));
48 }
49 
50 template <typename T>
Pointer(sqlite3_value * value,const char * type)51 inline T* Pointer(sqlite3_value* value, const char* type) {
52   return static_cast<T*>(sqlite3_value_pointer(value, type));
53 }
54 
55 }  // namespace perfetto::trace_processor::sqlite::value
56 
57 #endif  // SRC_TRACE_PROCESSOR_SQLITE_BINDINGS_SQLITE_VALUE_H_
58