@@ -12,44 +12,44 @@ namespace impeller {
1212ArchiveLocation::ArchiveLocation (Archive& context,
1313 ArchiveStatement& statement,
1414 const ArchiveClassRegistration& registration,
15- Archivable::ArchiveName name)
15+ std::optional< int64_t > name)
1616 : context_(context),
1717 statement_ (statement),
1818 registration_(registration),
1919 name_(name),
2020 current_class_(registration.GetClassName()) {}
2121
2222Archivable::ArchiveName ArchiveLocation::GetPrimaryKey () const {
23- return name_;
23+ return name_. value_or ( 0u ) ;
2424}
2525
2626bool ArchiveLocation::Write (ArchiveDef::Member member,
2727 const std::string& item) {
28- auto found = registration_.FindColumn (current_class_, member);
29- return found. second ? statement_.WriteValue (found. first , item) : false ;
28+ auto index = registration_.FindColumnIndex (current_class_, member);
29+ return index. has_value () ? statement_.WriteValue (index. value () , item) : false ;
3030}
3131
3232bool 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 ;
33+ auto index = registration_.FindColumnIndex (current_class_, member);
34+ return index. has_value () ? statement_.WriteValue (index. value () , item) : false ;
3535}
3636
3737bool 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 ;
38+ auto index = registration_.FindColumnIndex (current_class_, member);
39+ return index. has_value () ? statement_.WriteValue (index. value () , item) : false ;
4040}
4141
4242bool 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 ;
43+ auto index = registration_.FindColumnIndex (current_class_, member);
44+ return index. has_value () ? statement_.WriteValue (index. value () , item) : false ;
4545}
4646
4747bool ArchiveLocation::Write (ArchiveDef::Member member,
4848 const ArchiveDef& otherDef,
4949 const Archivable& other) {
50- auto found = registration_.FindColumn (current_class_, member);
50+ auto index = registration_.FindColumnIndex (current_class_, member);
5151
52- if (!found. second ) {
52+ if (!index. has_value () ) {
5353 return false ;
5454 }
5555
@@ -58,86 +58,76 @@ bool ArchiveLocation::Write(ArchiveDef::Member member,
5858 * have a name that is auto assigned. In that case, we cannot ask it before
5959 * archival (via `other.archiveName()`).
6060 */
61- int64_t lastInsert = 0 ;
62- if (!context_. ArchiveInstance (otherDef, other, lastInsert )) {
61+ auto row_id = context_. ArchiveInstance (otherDef, other) ;
62+ if (!row_id. has_value ( )) {
6363 return false ;
6464 }
6565
6666 /*
6767 * Bind the name of the serializable
6868 */
69- if (!statement_.WriteValue (found. first , lastInsert )) {
69+ if (!statement_.WriteValue (index. value (), row_id. value () )) {
7070 return false ;
7171 }
7272
7373 return true ;
7474}
7575
76- std::pair< bool , int64_t > ArchiveLocation::WriteVectorKeys (
76+ std::optional< int64_t > ArchiveLocation::WriteVectorKeys (
7777 std::vector<int64_t >&& members) {
7878 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};
79+ return context_.ArchiveInstance (ArchiveVector::ArchiveDefinition, vector);
8680}
8781
8882bool ArchiveLocation::ReadVectorKeys (Archivable::ArchiveName name,
8983 std::vector<int64_t >& members) {
9084 ArchiveVector vector;
91-
9285 if (!context_.UnarchiveInstance (ArchiveVector::ArchiveDefinition, name,
9386 vector)) {
9487 return false ;
9588 }
96-
9789 const auto & keys = vector.GetKeys ();
98-
9990 std::move (keys.begin (), keys.end (), std::back_inserter (members));
100-
10191 return true ;
10292}
10393
10494bool 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 ;
95+ auto index = registration_.FindColumnIndex (current_class_, member);
96+ return index. has_value () ? statement_.ReadValue (index. value () , item) : false ;
10797}
10898
10999bool 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 ;
100+ auto index = registration_.FindColumnIndex (current_class_, member);
101+ return index. has_value () ? statement_.ReadValue (index. value () , item) : false ;
112102}
113103
114104bool 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 ;
105+ auto index = registration_.FindColumnIndex (current_class_, member);
106+ return index. has_value () ? statement_.ReadValue (index. value () , item) : false ;
117107}
118108
119109bool 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 ;
110+ auto index = registration_.FindColumnIndex (current_class_, member);
111+ return index. has_value () ? statement_.ReadValue (index. value () , item) : false ;
122112}
123113
124114bool ArchiveLocation::Read (ArchiveDef::Member member,
125115 const ArchiveDef& otherDef,
126116 Archivable& other) {
127- auto found = registration_.FindColumn (current_class_, member);
117+ auto index = registration_.FindColumnIndex (current_class_, member);
128118
129119 /*
130120 * Make sure a member is present at that column
131121 */
132- if (!found. second ) {
122+ if (!index. has_value () ) {
133123 return false ;
134124 }
135125
136126 /*
137127 * Try to find the foreign key in the current items row
138128 */
139129 int64_t foreignKey = 0 ;
140- if (!statement_.ReadValue (found. first , foreignKey)) {
130+ if (!statement_.ReadValue (index. value () , foreignKey)) {
141131 return false ;
142132 }
143133
0 commit comments