Add uncommitted patches from a previous change.

This commit is contained in:
Chinmay Garde 2021-12-11 13:35:27 -08:00 committed by Dan Field
parent da06e76b5f
commit c2ec1e293c
2 changed files with 144 additions and 145 deletions

View File

@ -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

View File

@ -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