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