Flutter Impeller
archive_vector.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
6 
7 #include <sstream>
8 
10 
11 namespace impeller {
12 
13 ArchiveVector::ArchiveVector(std::vector<int64_t> keys)
14  : keys_(std::move(keys)) {}
15 
16 ArchiveVector::ArchiveVector() {}
17 
18 static constexpr const char* kVectorKeys = "keys";
19 
21  .table_name = "IPLR_vectors",
22  .members = {kVectorKeys},
23 };
24 
26  // Archive definition says the keys will be auto assigned.
27  return std::nullopt;
28 }
29 
30 const std::vector<int64_t> ArchiveVector::GetKeys() const {
31  return keys_;
32 }
33 
35  std::stringstream stream;
36  for (size_t i = 0, count = keys_.size(); i < count; i++) {
37  stream << keys_[i];
38  if (i != count - 1) {
39  stream << ",";
40  }
41  }
42  return item.Write(kVectorKeys, stream.str());
43 }
44 
46  std::string flattened;
47  if (!item.Read(kVectorKeys, flattened)) {
48  return false;
49  }
50 
51  std::stringstream stream(flattened);
52  int64_t single = 0;
53  while (stream >> single) {
54  keys_.emplace_back(single);
55  stream.ignore();
56  }
57 
58  return true;
59 }
60 
61 } // namespace impeller
impeller::ArchiveVector::Write
bool Write(ArchiveLocation &item) const override
Definition: archive_vector.cc:34
impeller::ArchiveVector::Read
bool Read(ArchiveLocation &item) override
Definition: archive_vector.cc:45
impeller::ArchiveDef::table_name
const std::string table_name
Definition: archivable.h:15
archive_location.h
impeller::ArchiveDef
Definition: archivable.h:14
impeller::ArchiveVector::kArchiveDefinition
static ArchiveDef kArchiveDefinition
Definition: archive_vector.h:14
impeller::PrimaryKey
std::optional< int64_t > PrimaryKey
Definition: archivable.h:21
impeller::ArchiveVector::GetPrimaryKey
PrimaryKey GetPrimaryKey() const override
Definition: archive_vector.cc:25
impeller::kVectorKeys
static constexpr const char * kVectorKeys
Definition: archive_vector.cc:18
impeller::ArchiveLocation::Read
bool Read(const std::string &member, T &item)
Definition: archive_location.h:79
impeller::ArchiveLocation
Definition: archive_location.h:21
std
Definition: comparable.h:98
archive_vector.h
impeller::ArchiveVector::GetKeys
const std::vector< int64_t > GetKeys() const
Definition: archive_vector.cc:30
impeller::ArchiveLocation::Write
bool Write(const std::string &member, T item)
Definition: archive_location.h:26
impeller
Definition: aiks_context.cc:10