| Flutter Impeller |

archive_statement.h
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #pragma once
6
7 #include <memory>
8 #include <type_traits>
9
10 #include "flutter/fml/macros.h"
11 #include "impeller/base/allocation.h"
12
13 namespace impeller {
14
15 //------------------------------------------------------------------------------
16 /// @brief Represents a read/write query to an archive database. Statements
17 /// are expensive to create and must be cached for as long as
18 /// possible.
19 ///
20 class ArchiveStatement {
21 public:
22 ~ArchiveStatement();
23
24 bool IsValid() const;
25
26 enum class Result {
27 //--------------------------------------------------------------------------
28 /// The statement is done executing.
29 ///
30 kDone,
31 //--------------------------------------------------------------------------
32 /// The statement found a row of information ready for reading.
33 ///
34 kRow,
35 //--------------------------------------------------------------------------
36 /// Statement execution was a failure.
37 ///
38 kFailure,
39 };
40
41 //----------------------------------------------------------------------------
42 /// @brief Execute the given statement with the provided data.
43 ///
44 /// @return Is the execution was succeessful.
45 ///
46 [[nodiscard]] Result Execute();
47
48 //----------------------------------------------------------------------------
49 /// @brief All writes after the last successfull `Run` call are reset.
50 /// Since statements are expensive to create, reset them for new
51 /// writes instead of creating new statements.
52 ///
53 /// @return If the statement writes were reset.
54 ///
55 bool Reset();
56
57 bool WriteValue(size_t index, const std::string& item);
58
59 template <class T, class = std::enable_if<std::is_integral<T>::value>>
60 bool WriteValue(size_t index, T item) {
61 return BindIntegral(index, static_cast<int64_t>(item));
62 }
63
64 bool WriteValue(size_t index, double item);
65
66 bool WriteValue(size_t index, const Allocation& item);
67
68 template <class T, class = std::enable_if<std::is_integral<T>::value>>
69 bool ReadValue(size_t index, T& item) {
70 return ColumnIntegral(index, item);
71 }
72
73 bool ReadValue(size_t index, double& item);
74
75 bool ReadValue(size_t index, std::string& item);
76
77 bool ReadValue(size_t index, Allocation& item);
78
79 size_t GetColumnCount();
80
81 private:
82 struct Handle;
83 std::unique_ptr<Handle> statement_handle_;
84
85 friend class ArchiveDatabase;
86
87 ArchiveStatement(void* db, const std::string& statement);
88
89 bool BindIntegral(size_t index, int64_t item);
90
91 bool ColumnIntegral(size_t index, int64_t& item);
92
93 FML_DISALLOW_COPY_AND_ASSIGN(ArchiveStatement);
94 };
95
96 } // namespace impeller
impeller::ArchiveStatement::Reset
bool Reset()
All writes after the last successfull Run call are reset. Since statements are expensive to create,...
Definition: archive_statement.cc:60
impeller::ArchiveStatement::Result
Result
Definition: archive_statement.h:26
allocation.h
impeller::ArchiveStatement::WriteValue
bool WriteValue(size_t index, T item)
Definition: archive_statement.h:60
impeller::ArchiveStatement::Result::kDone
@ kDone
impeller::ArchiveDatabase
A handle to the underlying database connection for an archive.
Definition: archive_database.h:23
impeller::ArchiveStatement::Execute
Result Execute()
Execute the given statement with the provided data.
Definition: archive_statement.cc:215
impeller::ArchiveStatement::WriteValue
bool WriteValue(size_t index, const std::string &item)
Definition: archive_statement.cc:99
impeller::ArchiveStatement
Represents a read/write query to an archive database. Statements are expensive to create and must be ...
Definition: archive_statement.h:20
impeller::ArchiveStatement::ReadValue
bool ReadValue(size_t index, T &item)
Definition: archive_statement.h:69
impeller::Allocation
Definition: allocation.h:15
impeller::ArchiveStatement::Result::kFailure
@ kFailure
impeller::ArchiveStatement::GetColumnCount
size_t GetColumnCount()
Definition: archive_statement.cc:89
impeller::ArchiveStatement::Result::kRow
@ kRow
impeller::ArchiveStatement::~ArchiveStatement
~ArchiveStatement()
impeller
Definition: aiks_context.cc:10
impeller::ArchiveStatement::IsValid
bool IsValid() const
Definition: archive_statement.cc:56