Skip to content

Commit 89589cc

Browse files
chinmaygardednfield
authored andcommitted
Separate archive_location into its own TU.
1 parent 8d7d8e6 commit 89589cc

16 files changed

+300
-232
lines changed

impeller/archivist/BUILD.gn

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ impeller_component("archivist") {
1919
"archive_class_registration.h",
2020
"archive_database.cc",
2121
"archive_database.h",
22+
"archive_location.cc",
23+
"archive_location.h",
2224
"archive_statement.cc",
2325
"archive_statement.h",
2426
"archive_transaction.cc",

impeller/archivist/archivable.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,21 @@
55
#pragma once
66

77
#include <cstdint>
8+
#include <string>
9+
#include <vector>
810

911
namespace impeller {
1012

13+
struct ArchiveDef {
14+
using Member = uint64_t;
15+
using Members = std::vector<Member>;
16+
17+
const ArchiveDef* isa = nullptr;
18+
const std::string table_name;
19+
const bool auto_key = true;
20+
const Members members;
21+
};
22+
1123
class ArchiveLocation;
1224

1325
//------------------------------------------------------------------------------

impeller/archivist/archive.cc

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "flutter/fml/logging.h"
1010
#include "impeller/archivist/archive_class_registration.h"
1111
#include "impeller/archivist/archive_database.h"
12+
#include "impeller/archivist/archive_location.h"
1213
#include "impeller/archivist/archive_statement.h"
1314
#include "impeller/archivist/archive_vector.h"
1415

@@ -22,14 +23,14 @@ Archive::~Archive() {
2223
<< "There must be no pending transactions";
2324
}
2425

25-
bool Archive::IsReady() const {
26-
return database_->IsReady();
26+
bool Archive::IsValid() const {
27+
return database_->IsValid();
2728
}
2829

2930
bool Archive::ArchiveInstance(const ArchiveDef& definition,
3031
const Archivable& archivable,
3132
int64_t& lastInsertIDOut) {
32-
if (!IsReady()) {
33+
if (!IsValid()) {
3334
return false;
3435
}
3536

@@ -44,7 +45,7 @@ bool Archive::ArchiveInstance(const ArchiveDef& definition,
4445

4546
auto statement = registration->GetInsertStatement();
4647

47-
if (!statement.IsReady() || !statement.Reset()) {
48+
if (!statement.IsValid() || !statement.Reset()) {
4849
/*
4950
* Must be able to reset the statement for a new write
5051
*/
@@ -73,7 +74,7 @@ bool Archive::ArchiveInstance(const ArchiveDef& definition,
7374
return false;
7475
}
7576

76-
if (statement.Run() != ArchiveStatement::Result::kDone) {
77+
if (statement.Execute() != ArchiveStatement::Result::kDone) {
7778
return false;
7879
}
7980

@@ -108,7 +109,7 @@ bool Archive::UnarchiveInstance(const ArchiveDef& definition,
108109
size_t Archive::UnarchiveInstances(const ArchiveDef& definition,
109110
Archive::UnarchiveStep stepper,
110111
Archivable::ArchiveName name) {
111-
if (!IsReady()) {
112+
if (!IsValid()) {
112113
return 0;
113114
}
114115

@@ -123,7 +124,7 @@ size_t Archive::UnarchiveInstances(const ArchiveDef& definition,
123124

124125
auto statement = registration->GetQueryStatement(isQueryingSingle);
125126

126-
if (!statement.IsReady() || !statement.Reset()) {
127+
if (!statement.IsValid() || !statement.Reset()) {
127128
return 0;
128129
}
129130

@@ -150,7 +151,7 @@ size_t Archive::UnarchiveInstances(const ArchiveDef& definition,
150151

151152
size_t itemsRead = 0;
152153

153-
while (statement.Run() == ArchiveStatement::Result::kRow) {
154+
while (statement.Execute() == ArchiveStatement::Result::kRow) {
154155
itemsRead++;
155156

156157
/*

impeller/archivist/archive.h

Lines changed: 1 addition & 192 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,11 @@
1111

1212
#include "flutter/fml/macros.h"
1313
#include "impeller/archivist/archivable.h"
14-
#include "impeller/base/allocation.h"
1514

1615
namespace impeller {
1716

1817
class ArchiveLocation;
19-
class ArchiveClassRegistration;
2018
class ArchiveDatabase;
21-
class ArchiveStatement;
22-
23-
struct ArchiveDef {
24-
using Member = uint64_t;
25-
using Members = std::vector<Member>;
26-
27-
const ArchiveDef* isa = nullptr;
28-
const std::string table_name;
29-
const bool auto_key = true;
30-
const Members members;
31-
};
3219

3320
static const Archivable::ArchiveName ArchiveNameAuto = 0;
3421

@@ -38,7 +25,7 @@ class Archive {
3825

3926
~Archive();
4027

41-
bool IsReady() const;
28+
bool IsValid() const;
4229

4330
template <class T,
4431
class = std::enable_if<std::is_base_of<Archivable, T>::value>>
@@ -83,182 +70,4 @@ class Archive {
8370
FML_DISALLOW_COPY_AND_ASSIGN(Archive);
8471
};
8572

86-
class ArchiveLocation {
87-
public:
88-
template <class T, class = std::enable_if<std::is_integral<T>::value>>
89-
bool Write(ArchiveDef::Member member, T item) {
90-
return WriteIntegral(member, static_cast<int64_t>(item));
91-
}
92-
93-
bool Write(ArchiveDef::Member member, double item);
94-
95-
bool Write(ArchiveDef::Member member, const std::string& item);
96-
97-
bool Write(ArchiveDef::Member member, const Allocation& allocation);
98-
99-
template <class T,
100-
class = std::enable_if<std::is_base_of<Archivable, T>::value>>
101-
bool WriteArchivable(ArchiveDef::Member member, const T& other) {
102-
const ArchiveDef& otherDef = T::ArchiveDefinition;
103-
return Write(member, otherDef, other);
104-
}
105-
106-
template <class T, class = std::enable_if<std::is_enum<T>::value>>
107-
bool WriteEnum(ArchiveDef::Member member, const T& item) {
108-
return WriteIntegral(member, static_cast<int64_t>(item));
109-
}
110-
111-
template <class T,
112-
class = std::enable_if<std::is_base_of<Archivable, T>::value>>
113-
bool Write(ArchiveDef::Member member, const std::vector<T>& items) {
114-
/*
115-
* All items in the vector are individually encoded and their keys noted
116-
*/
117-
std::vector<int64_t> members;
118-
members.reserve(items.size());
119-
120-
const ArchiveDef& itemDefinition = T::ArchiveDefinition;
121-
for (const auto& item : items) {
122-
int64_t added = 0;
123-
bool result = context_.ArchiveInstance(itemDefinition, item, added);
124-
if (!result) {
125-
return false;
126-
}
127-
members.emplace_back(added);
128-
}
129-
130-
/*
131-
* The keys are flattened into the vectors table. Write to that table
132-
*/
133-
auto vectorInsert = WriteVectorKeys(std::move(members));
134-
135-
if (!vectorInsert.first) {
136-
return false;
137-
}
138-
139-
return WriteIntegral(member, vectorInsert.second);
140-
}
141-
142-
template <class Super,
143-
class Current,
144-
class = std::enable_if<std::is_base_of<Archivable, Super>::value &&
145-
std::is_base_of<Archivable, Current>::value>>
146-
bool WriteSuper(const Current& thiz) {
147-
std::string oldClass = current_class_;
148-
current_class_ = Super::ArchiveDefinition.className;
149-
auto success = thiz.Super::serialize(*this);
150-
current_class_ = oldClass;
151-
return success;
152-
}
153-
154-
template <class T, class = std::enable_if<std::is_integral<T>::value>>
155-
bool Read(ArchiveDef::Member member, T& item) {
156-
int64_t decoded = 0;
157-
auto result = ReadIntegral(member, decoded);
158-
item = static_cast<T>(decoded);
159-
return result;
160-
}
161-
162-
bool Read(ArchiveDef::Member member, double& item);
163-
164-
bool Read(ArchiveDef::Member member, std::string& item);
165-
166-
bool Read(ArchiveDef::Member member, Allocation& allocation);
167-
168-
template <class T,
169-
class = std::enable_if<std::is_base_of<Archivable, T>::value>>
170-
bool ReadArchivable(ArchiveDef::Member member, T& other) {
171-
const ArchiveDef& otherDef = T::ArchiveDefinition;
172-
return decode(member, otherDef, other);
173-
}
174-
175-
template <class T, class = std::enable_if<std::is_enum<T>::value>>
176-
bool ReadEnum(ArchiveDef::Member member, T& item) {
177-
int64_t desugared = 0;
178-
if (ReadIntegral(member, desugared)) {
179-
item = static_cast<T>(desugared);
180-
return true;
181-
}
182-
return false;
183-
}
184-
185-
template <class T,
186-
class = std::enable_if<std::is_base_of<Archivable, T>::value>>
187-
bool Read(ArchiveDef::Member member, std::vector<T>& items) {
188-
/*
189-
* From the member, find the foreign key of the vector
190-
*/
191-
int64_t vectorForeignKey = 0;
192-
if (!ReadIntegral(member, vectorForeignKey)) {
193-
return false;
194-
}
195-
196-
/*
197-
* Get vector keys
198-
*/
199-
std::vector<int64_t> keys;
200-
if (!ReadVectorKeys(vectorForeignKey, keys)) {
201-
return false;
202-
}
203-
204-
const ArchiveDef& otherDef = T::ArchiveDefinition;
205-
for (const auto& key : keys) {
206-
items.emplace_back();
207-
208-
if (!context_.UnarchiveInstance(otherDef, key, items.back())) {
209-
return false;
210-
}
211-
}
212-
213-
return true;
214-
}
215-
216-
template <class Super,
217-
class Current,
218-
class = std::enable_if<std::is_base_of<Archivable, Super>::value &&
219-
std::is_base_of<Archivable, Current>::value>>
220-
bool ReadSuper(Current& thiz) {
221-
std::string oldClass = current_class_;
222-
current_class_ = Super::ArchiveDefinition.className;
223-
auto success = thiz.Super::deserialize(*this);
224-
current_class_ = oldClass;
225-
return success;
226-
}
227-
228-
Archivable::ArchiveName Name() const;
229-
230-
private:
231-
Archive& context_;
232-
ArchiveStatement& statement_;
233-
const ArchiveClassRegistration& registration_;
234-
Archivable::ArchiveName name_;
235-
std::string current_class_;
236-
237-
friend class Archive;
238-
239-
ArchiveLocation(Archive& context,
240-
ArchiveStatement& statement,
241-
const ArchiveClassRegistration& registration,
242-
Archivable::ArchiveName name);
243-
244-
bool WriteIntegral(ArchiveDef::Member member, int64_t item);
245-
246-
bool ReadIntegral(ArchiveDef::Member member, int64_t& item);
247-
248-
std::pair<bool, int64_t> WriteVectorKeys(std::vector<int64_t>&& members);
249-
250-
bool ReadVectorKeys(Archivable::ArchiveName name,
251-
std::vector<int64_t>& members);
252-
253-
bool Write(ArchiveDef::Member member,
254-
const ArchiveDef& otherDef,
255-
const Archivable& other);
256-
257-
bool Read(ArchiveDef::Member member,
258-
const ArchiveDef& otherDef,
259-
Archivable& other);
260-
261-
FML_DISALLOW_COPY_AND_ASSIGN(ArchiveLocation);
262-
};
263-
26473
} // namespace impeller

impeller/archivist/archive_class_registration.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ size_t ArchiveClassRegistration::GetMemberCount() const {
4545
return member_count_;
4646
}
4747

48-
bool ArchiveClassRegistration::IsReady() const {
48+
bool ArchiveClassRegistration::IsValid() const {
4949
return is_ready_;
5050
}
5151

@@ -98,15 +98,15 @@ bool ArchiveClassRegistration::CreateTable(bool autoIncrement) {
9898

9999
auto statement = database_.CreateStatement(stream.str());
100100

101-
if (!statement.IsReady()) {
101+
if (!statement.IsValid()) {
102102
return false;
103103
}
104104

105105
if (!statement.Reset()) {
106106
return false;
107107
}
108108

109-
return statement.Run() == ArchiveStatement::Result::kDone;
109+
return statement.Execute() == ArchiveStatement::Result::kDone;
110110
}
111111

112112
ArchiveStatement ArchiveClassRegistration::GetQueryStatement(

impeller/archivist/archive_class_registration.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include "flutter/fml/macros.h"
88
#include "impeller/archivist/archive.h"
9+
#include "impeller/archivist/archive_statement.h"
910

1011
namespace impeller {
1112

@@ -19,7 +20,7 @@ class ArchiveClassRegistration {
1920

2021
size_t GetMemberCount() const;
2122

22-
bool IsReady() const;
23+
bool IsValid() const;
2324

2425
ArchiveStatement GetInsertStatement() const;
2526

0 commit comments

Comments
 (0)