mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Add uncommitted patches from a previous change.
This commit is contained in:
parent
da06e76b5f
commit
c2ec1e293c
@ -10,8 +10,6 @@
|
||||
#include "impeller/archivist/archive_class_registration.h"
|
||||
#include "impeller/archivist/archive_database.h"
|
||||
#include "impeller/archivist/archive_location.h"
|
||||
#include "impeller/archivist/archive_statement.h"
|
||||
#include "impeller/archivist/archive_vector.h"
|
||||
|
||||
namespace impeller {
|
||||
|
||||
@ -173,146 +171,4 @@ size_t Archive::UnarchiveInstances(const ArchiveDef& definition,
|
||||
return itemsRead;
|
||||
}
|
||||
|
||||
ArchiveLocation::ArchiveLocation(Archive& context,
|
||||
ArchiveStatement& statement,
|
||||
const ArchiveClassRegistration& registration,
|
||||
Archivable::ArchiveName name)
|
||||
: context_(context),
|
||||
statement_(statement),
|
||||
registration_(registration),
|
||||
name_(name),
|
||||
current_class_(registration.GetClassName()) {}
|
||||
|
||||
Archivable::ArchiveName ArchiveLocation::GetPrimaryKey() const {
|
||||
return name_;
|
||||
}
|
||||
|
||||
bool ArchiveLocation::Write(ArchiveDef::Member member,
|
||||
const std::string& item) {
|
||||
auto found = registration_.FindColumn(current_class_, member);
|
||||
return found.second ? statement_.WriteValue(found.first, item) : false;
|
||||
}
|
||||
|
||||
bool ArchiveLocation::WriteIntegral(ArchiveDef::Member member, int64_t item) {
|
||||
auto found = registration_.FindColumn(current_class_, member);
|
||||
return found.second ? statement_.WriteValue(found.first, item) : false;
|
||||
}
|
||||
|
||||
bool ArchiveLocation::Write(ArchiveDef::Member member, double item) {
|
||||
auto found = registration_.FindColumn(current_class_, member);
|
||||
return found.second ? statement_.WriteValue(found.first, item) : false;
|
||||
}
|
||||
|
||||
bool ArchiveLocation::Write(ArchiveDef::Member member, const Allocation& item) {
|
||||
auto found = registration_.FindColumn(current_class_, member);
|
||||
return found.second ? statement_.WriteValue(found.first, item) : false;
|
||||
}
|
||||
|
||||
bool ArchiveLocation::Write(ArchiveDef::Member member,
|
||||
const ArchiveDef& otherDef,
|
||||
const Archivable& other) {
|
||||
auto found = registration_.FindColumn(current_class_, member);
|
||||
|
||||
if (!found.second) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* We need to fully archive the other instance first because it could
|
||||
* have a name that is auto assigned. In that case, we cannot ask it before
|
||||
* archival (via `other.archiveName()`).
|
||||
*/
|
||||
int64_t lastInsert = 0;
|
||||
if (!context_.ArchiveInstance(otherDef, other, lastInsert)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Bind the name of the serializable
|
||||
*/
|
||||
if (!statement_.WriteValue(found.first, lastInsert)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
std::pair<bool, int64_t> ArchiveLocation::WriteVectorKeys(
|
||||
std::vector<int64_t>&& members) {
|
||||
ArchiveVector vector(std::move(members));
|
||||
int64_t vectorID = 0;
|
||||
if (!context_.ArchiveInstance(ArchiveVector::ArchiveDefinition, //
|
||||
vector, //
|
||||
vectorID)) {
|
||||
return {false, 0};
|
||||
}
|
||||
return {true, vectorID};
|
||||
}
|
||||
|
||||
bool ArchiveLocation::ReadVectorKeys(Archivable::ArchiveName name,
|
||||
std::vector<int64_t>& members) {
|
||||
ArchiveVector vector;
|
||||
|
||||
if (!context_.UnarchiveInstance(ArchiveVector::ArchiveDefinition, name,
|
||||
vector)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto& keys = vector.GetKeys();
|
||||
|
||||
std::move(keys.begin(), keys.end(), std::back_inserter(members));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ArchiveLocation::Read(ArchiveDef::Member member, std::string& item) {
|
||||
auto found = registration_.FindColumn(current_class_, member);
|
||||
return found.second ? statement_.ReadValue(found.first, item) : false;
|
||||
}
|
||||
|
||||
bool ArchiveLocation::ReadIntegral(ArchiveDef::Member member, int64_t& item) {
|
||||
auto found = registration_.FindColumn(current_class_, member);
|
||||
return found.second ? statement_.ReadValue(found.first, item) : false;
|
||||
}
|
||||
|
||||
bool ArchiveLocation::Read(ArchiveDef::Member member, double& item) {
|
||||
auto found = registration_.FindColumn(current_class_, member);
|
||||
return found.second ? statement_.ReadValue(found.first, item) : false;
|
||||
}
|
||||
|
||||
bool ArchiveLocation::Read(ArchiveDef::Member member, Allocation& item) {
|
||||
auto found = registration_.FindColumn(current_class_, member);
|
||||
return found.second ? statement_.ReadValue(found.first, item) : false;
|
||||
}
|
||||
|
||||
bool ArchiveLocation::Read(ArchiveDef::Member member,
|
||||
const ArchiveDef& otherDef,
|
||||
Archivable& other) {
|
||||
auto found = registration_.FindColumn(current_class_, member);
|
||||
|
||||
/*
|
||||
* Make sure a member is present at that column
|
||||
*/
|
||||
if (!found.second) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Try to find the foreign key in the current items row
|
||||
*/
|
||||
int64_t foreignKey = 0;
|
||||
if (!statement_.ReadValue(found.first, foreignKey)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Find the other item and unarchive by this foreign key
|
||||
*/
|
||||
if (!context_.UnarchiveInstance(otherDef, foreignKey, other)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace impeller
|
||||
|
||||
@ -4,8 +4,151 @@
|
||||
|
||||
#include "impeller/archivist/archive_location.h"
|
||||
|
||||
#include "impeller/archivist/archive_class_registration.h"
|
||||
#include "impeller/archivist/archive_vector.h"
|
||||
|
||||
namespace impeller {
|
||||
|
||||
//
|
||||
ArchiveLocation::ArchiveLocation(Archive& context,
|
||||
ArchiveStatement& statement,
|
||||
const ArchiveClassRegistration& registration,
|
||||
Archivable::ArchiveName name)
|
||||
: context_(context),
|
||||
statement_(statement),
|
||||
registration_(registration),
|
||||
name_(name),
|
||||
current_class_(registration.GetClassName()) {}
|
||||
|
||||
Archivable::ArchiveName ArchiveLocation::GetPrimaryKey() const {
|
||||
return name_;
|
||||
}
|
||||
|
||||
bool ArchiveLocation::Write(ArchiveDef::Member member,
|
||||
const std::string& item) {
|
||||
auto found = registration_.FindColumn(current_class_, member);
|
||||
return found.second ? statement_.WriteValue(found.first, item) : false;
|
||||
}
|
||||
|
||||
bool ArchiveLocation::WriteIntegral(ArchiveDef::Member member, int64_t item) {
|
||||
auto found = registration_.FindColumn(current_class_, member);
|
||||
return found.second ? statement_.WriteValue(found.first, item) : false;
|
||||
}
|
||||
|
||||
bool ArchiveLocation::Write(ArchiveDef::Member member, double item) {
|
||||
auto found = registration_.FindColumn(current_class_, member);
|
||||
return found.second ? statement_.WriteValue(found.first, item) : false;
|
||||
}
|
||||
|
||||
bool ArchiveLocation::Write(ArchiveDef::Member member, const Allocation& item) {
|
||||
auto found = registration_.FindColumn(current_class_, member);
|
||||
return found.second ? statement_.WriteValue(found.first, item) : false;
|
||||
}
|
||||
|
||||
bool ArchiveLocation::Write(ArchiveDef::Member member,
|
||||
const ArchiveDef& otherDef,
|
||||
const Archivable& other) {
|
||||
auto found = registration_.FindColumn(current_class_, member);
|
||||
|
||||
if (!found.second) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* We need to fully archive the other instance first because it could
|
||||
* have a name that is auto assigned. In that case, we cannot ask it before
|
||||
* archival (via `other.archiveName()`).
|
||||
*/
|
||||
int64_t lastInsert = 0;
|
||||
if (!context_.ArchiveInstance(otherDef, other, lastInsert)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Bind the name of the serializable
|
||||
*/
|
||||
if (!statement_.WriteValue(found.first, lastInsert)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
std::pair<bool, int64_t> ArchiveLocation::WriteVectorKeys(
|
||||
std::vector<int64_t>&& members) {
|
||||
ArchiveVector vector(std::move(members));
|
||||
int64_t vectorID = 0;
|
||||
if (!context_.ArchiveInstance(ArchiveVector::ArchiveDefinition, //
|
||||
vector, //
|
||||
vectorID)) {
|
||||
return {false, 0};
|
||||
}
|
||||
return {true, vectorID};
|
||||
}
|
||||
|
||||
bool ArchiveLocation::ReadVectorKeys(Archivable::ArchiveName name,
|
||||
std::vector<int64_t>& members) {
|
||||
ArchiveVector vector;
|
||||
|
||||
if (!context_.UnarchiveInstance(ArchiveVector::ArchiveDefinition, name,
|
||||
vector)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto& keys = vector.GetKeys();
|
||||
|
||||
std::move(keys.begin(), keys.end(), std::back_inserter(members));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ArchiveLocation::Read(ArchiveDef::Member member, std::string& item) {
|
||||
auto found = registration_.FindColumn(current_class_, member);
|
||||
return found.second ? statement_.ReadValue(found.first, item) : false;
|
||||
}
|
||||
|
||||
bool ArchiveLocation::ReadIntegral(ArchiveDef::Member member, int64_t& item) {
|
||||
auto found = registration_.FindColumn(current_class_, member);
|
||||
return found.second ? statement_.ReadValue(found.first, item) : false;
|
||||
}
|
||||
|
||||
bool ArchiveLocation::Read(ArchiveDef::Member member, double& item) {
|
||||
auto found = registration_.FindColumn(current_class_, member);
|
||||
return found.second ? statement_.ReadValue(found.first, item) : false;
|
||||
}
|
||||
|
||||
bool ArchiveLocation::Read(ArchiveDef::Member member, Allocation& item) {
|
||||
auto found = registration_.FindColumn(current_class_, member);
|
||||
return found.second ? statement_.ReadValue(found.first, item) : false;
|
||||
}
|
||||
|
||||
bool ArchiveLocation::Read(ArchiveDef::Member member,
|
||||
const ArchiveDef& otherDef,
|
||||
Archivable& other) {
|
||||
auto found = registration_.FindColumn(current_class_, member);
|
||||
|
||||
/*
|
||||
* Make sure a member is present at that column
|
||||
*/
|
||||
if (!found.second) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Try to find the foreign key in the current items row
|
||||
*/
|
||||
int64_t foreignKey = 0;
|
||||
if (!statement_.ReadValue(found.first, foreignKey)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Find the other item and unarchive by this foreign key
|
||||
*/
|
||||
if (!context_.UnarchiveInstance(otherDef, foreignKey, other)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace impeller
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user