Skip to content

Commit 4a6e2d0

Browse files
chinmaygardednfield
authored andcommitted
Add uncommitted patches from a previous change.
1 parent 547fc00 commit 4a6e2d0

File tree

2 files changed

+144
-145
lines changed

2 files changed

+144
-145
lines changed

impeller/archivist/archive.cc

Lines changed: 0 additions & 144 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
#include "impeller/archivist/archive_class_registration.h"
1111
#include "impeller/archivist/archive_database.h"
1212
#include "impeller/archivist/archive_location.h"
13-
#include "impeller/archivist/archive_statement.h"
14-
#include "impeller/archivist/archive_vector.h"
1513

1614
namespace impeller {
1715

@@ -173,146 +171,4 @@ size_t Archive::UnarchiveInstances(const ArchiveDef& definition,
173171
return itemsRead;
174172
}
175173

176-
ArchiveLocation::ArchiveLocation(Archive& context,
177-
ArchiveStatement& statement,
178-
const ArchiveClassRegistration& registration,
179-
Archivable::ArchiveName name)
180-
: context_(context),
181-
statement_(statement),
182-
registration_(registration),
183-
name_(name),
184-
current_class_(registration.GetClassName()) {}
185-
186-
Archivable::ArchiveName ArchiveLocation::GetPrimaryKey() const {
187-
return name_;
188-
}
189-
190-
bool ArchiveLocation::Write(ArchiveDef::Member member,
191-
const std::string& item) {
192-
auto found = registration_.FindColumn(current_class_, member);
193-
return found.second ? statement_.WriteValue(found.first, item) : false;
194-
}
195-
196-
bool ArchiveLocation::WriteIntegral(ArchiveDef::Member member, int64_t item) {
197-
auto found = registration_.FindColumn(current_class_, member);
198-
return found.second ? statement_.WriteValue(found.first, item) : false;
199-
}
200-
201-
bool ArchiveLocation::Write(ArchiveDef::Member member, double item) {
202-
auto found = registration_.FindColumn(current_class_, member);
203-
return found.second ? statement_.WriteValue(found.first, item) : false;
204-
}
205-
206-
bool ArchiveLocation::Write(ArchiveDef::Member member, const Allocation& item) {
207-
auto found = registration_.FindColumn(current_class_, member);
208-
return found.second ? statement_.WriteValue(found.first, item) : false;
209-
}
210-
211-
bool ArchiveLocation::Write(ArchiveDef::Member member,
212-
const ArchiveDef& otherDef,
213-
const Archivable& other) {
214-
auto found = registration_.FindColumn(current_class_, member);
215-
216-
if (!found.second) {
217-
return false;
218-
}
219-
220-
/*
221-
* We need to fully archive the other instance first because it could
222-
* have a name that is auto assigned. In that case, we cannot ask it before
223-
* archival (via `other.archiveName()`).
224-
*/
225-
int64_t lastInsert = 0;
226-
if (!context_.ArchiveInstance(otherDef, other, lastInsert)) {
227-
return false;
228-
}
229-
230-
/*
231-
* Bind the name of the serializable
232-
*/
233-
if (!statement_.WriteValue(found.first, lastInsert)) {
234-
return false;
235-
}
236-
237-
return true;
238-
}
239-
240-
std::pair<bool, int64_t> ArchiveLocation::WriteVectorKeys(
241-
std::vector<int64_t>&& members) {
242-
ArchiveVector vector(std::move(members));
243-
int64_t vectorID = 0;
244-
if (!context_.ArchiveInstance(ArchiveVector::ArchiveDefinition, //
245-
vector, //
246-
vectorID)) {
247-
return {false, 0};
248-
}
249-
return {true, vectorID};
250-
}
251-
252-
bool ArchiveLocation::ReadVectorKeys(Archivable::ArchiveName name,
253-
std::vector<int64_t>& members) {
254-
ArchiveVector vector;
255-
256-
if (!context_.UnarchiveInstance(ArchiveVector::ArchiveDefinition, name,
257-
vector)) {
258-
return false;
259-
}
260-
261-
const auto& keys = vector.GetKeys();
262-
263-
std::move(keys.begin(), keys.end(), std::back_inserter(members));
264-
265-
return true;
266-
}
267-
268-
bool ArchiveLocation::Read(ArchiveDef::Member member, std::string& item) {
269-
auto found = registration_.FindColumn(current_class_, member);
270-
return found.second ? statement_.ReadValue(found.first, item) : false;
271-
}
272-
273-
bool ArchiveLocation::ReadIntegral(ArchiveDef::Member member, int64_t& item) {
274-
auto found = registration_.FindColumn(current_class_, member);
275-
return found.second ? statement_.ReadValue(found.first, item) : false;
276-
}
277-
278-
bool ArchiveLocation::Read(ArchiveDef::Member member, double& item) {
279-
auto found = registration_.FindColumn(current_class_, member);
280-
return found.second ? statement_.ReadValue(found.first, item) : false;
281-
}
282-
283-
bool ArchiveLocation::Read(ArchiveDef::Member member, Allocation& item) {
284-
auto found = registration_.FindColumn(current_class_, member);
285-
return found.second ? statement_.ReadValue(found.first, item) : false;
286-
}
287-
288-
bool ArchiveLocation::Read(ArchiveDef::Member member,
289-
const ArchiveDef& otherDef,
290-
Archivable& other) {
291-
auto found = registration_.FindColumn(current_class_, member);
292-
293-
/*
294-
* Make sure a member is present at that column
295-
*/
296-
if (!found.second) {
297-
return false;
298-
}
299-
300-
/*
301-
* Try to find the foreign key in the current items row
302-
*/
303-
int64_t foreignKey = 0;
304-
if (!statement_.ReadValue(found.first, foreignKey)) {
305-
return false;
306-
}
307-
308-
/*
309-
* Find the other item and unarchive by this foreign key
310-
*/
311-
if (!context_.UnarchiveInstance(otherDef, foreignKey, other)) {
312-
return false;
313-
}
314-
315-
return true;
316-
}
317-
318174
} // namespace impeller

impeller/archivist/archive_location.cc

Lines changed: 144 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,151 @@
44

55
#include "impeller/archivist/archive_location.h"
66

7+
#include "impeller/archivist/archive_class_registration.h"
8+
#include "impeller/archivist/archive_vector.h"
9+
710
namespace impeller {
811

9-
//
12+
ArchiveLocation::ArchiveLocation(Archive& context,
13+
ArchiveStatement& statement,
14+
const ArchiveClassRegistration& registration,
15+
Archivable::ArchiveName name)
16+
: context_(context),
17+
statement_(statement),
18+
registration_(registration),
19+
name_(name),
20+
current_class_(registration.GetClassName()) {}
21+
22+
Archivable::ArchiveName ArchiveLocation::GetPrimaryKey() const {
23+
return name_;
24+
}
25+
26+
bool ArchiveLocation::Write(ArchiveDef::Member member,
27+
const std::string& item) {
28+
auto found = registration_.FindColumn(current_class_, member);
29+
return found.second ? statement_.WriteValue(found.first, item) : false;
30+
}
31+
32+
bool ArchiveLocation::WriteIntegral(ArchiveDef::Member member, int64_t item) {
33+
auto found = registration_.FindColumn(current_class_, member);
34+
return found.second ? statement_.WriteValue(found.first, item) : false;
35+
}
36+
37+
bool ArchiveLocation::Write(ArchiveDef::Member member, double item) {
38+
auto found = registration_.FindColumn(current_class_, member);
39+
return found.second ? statement_.WriteValue(found.first, item) : false;
40+
}
41+
42+
bool ArchiveLocation::Write(ArchiveDef::Member member, const Allocation& item) {
43+
auto found = registration_.FindColumn(current_class_, member);
44+
return found.second ? statement_.WriteValue(found.first, item) : false;
45+
}
46+
47+
bool ArchiveLocation::Write(ArchiveDef::Member member,
48+
const ArchiveDef& otherDef,
49+
const Archivable& other) {
50+
auto found = registration_.FindColumn(current_class_, member);
51+
52+
if (!found.second) {
53+
return false;
54+
}
55+
56+
/*
57+
* We need to fully archive the other instance first because it could
58+
* have a name that is auto assigned. In that case, we cannot ask it before
59+
* archival (via `other.archiveName()`).
60+
*/
61+
int64_t lastInsert = 0;
62+
if (!context_.ArchiveInstance(otherDef, other, lastInsert)) {
63+
return false;
64+
}
65+
66+
/*
67+
* Bind the name of the serializable
68+
*/
69+
if (!statement_.WriteValue(found.first, lastInsert)) {
70+
return false;
71+
}
72+
73+
return true;
74+
}
75+
76+
std::pair<bool, int64_t> ArchiveLocation::WriteVectorKeys(
77+
std::vector<int64_t>&& members) {
78+
ArchiveVector vector(std::move(members));
79+
int64_t vectorID = 0;
80+
if (!context_.ArchiveInstance(ArchiveVector::ArchiveDefinition, //
81+
vector, //
82+
vectorID)) {
83+
return {false, 0};
84+
}
85+
return {true, vectorID};
86+
}
87+
88+
bool ArchiveLocation::ReadVectorKeys(Archivable::ArchiveName name,
89+
std::vector<int64_t>& members) {
90+
ArchiveVector vector;
91+
92+
if (!context_.UnarchiveInstance(ArchiveVector::ArchiveDefinition, name,
93+
vector)) {
94+
return false;
95+
}
96+
97+
const auto& keys = vector.GetKeys();
98+
99+
std::move(keys.begin(), keys.end(), std::back_inserter(members));
100+
101+
return true;
102+
}
103+
104+
bool ArchiveLocation::Read(ArchiveDef::Member member, std::string& item) {
105+
auto found = registration_.FindColumn(current_class_, member);
106+
return found.second ? statement_.ReadValue(found.first, item) : false;
107+
}
108+
109+
bool ArchiveLocation::ReadIntegral(ArchiveDef::Member member, int64_t& item) {
110+
auto found = registration_.FindColumn(current_class_, member);
111+
return found.second ? statement_.ReadValue(found.first, item) : false;
112+
}
113+
114+
bool ArchiveLocation::Read(ArchiveDef::Member member, double& item) {
115+
auto found = registration_.FindColumn(current_class_, member);
116+
return found.second ? statement_.ReadValue(found.first, item) : false;
117+
}
118+
119+
bool ArchiveLocation::Read(ArchiveDef::Member member, Allocation& item) {
120+
auto found = registration_.FindColumn(current_class_, member);
121+
return found.second ? statement_.ReadValue(found.first, item) : false;
122+
}
123+
124+
bool ArchiveLocation::Read(ArchiveDef::Member member,
125+
const ArchiveDef& otherDef,
126+
Archivable& other) {
127+
auto found = registration_.FindColumn(current_class_, member);
128+
129+
/*
130+
* Make sure a member is present at that column
131+
*/
132+
if (!found.second) {
133+
return false;
134+
}
135+
136+
/*
137+
* Try to find the foreign key in the current items row
138+
*/
139+
int64_t foreignKey = 0;
140+
if (!statement_.ReadValue(found.first, foreignKey)) {
141+
return false;
142+
}
143+
144+
/*
145+
* Find the other item and unarchive by this foreign key
146+
*/
147+
if (!context_.UnarchiveInstance(otherDef, foreignKey, other)) {
148+
return false;
149+
}
150+
151+
return true;
152+
}
10153

11154
} // namespace impeller

0 commit comments

Comments
 (0)