diff options
Diffstat (limited to 'komfydb/common/tuple.cc')
-rw-r--r-- | komfydb/common/tuple.cc | 31 |
1 files changed, 8 insertions, 23 deletions
diff --git a/komfydb/common/tuple.cc b/komfydb/common/tuple.cc index 71544ce..4658260 100644 --- a/komfydb/common/tuple.cc +++ b/komfydb/common/tuple.cc @@ -9,24 +9,6 @@ namespace komfydb::common { Tuple::Tuple(const TupleDesc* td) : td(td) { fields.resize(td->Length()); - for (int i = 0; i < td->Length(); i++) { - switch (td->GetFieldType(i)->GetValue()) { - case Type::INT: - fields[i] = new IntField(0); - break; - case Type::STRING: - fields[i] = new StringField(""); - break; - default: - assert(false); - } - } -} - -Tuple::~Tuple() { - for (auto f : fields) { - delete f; - } } const TupleDesc* Tuple::GetTupleDesc() { @@ -37,20 +19,23 @@ absl::StatusOr<Field*> Tuple::GetField(int i) { if (fields.size() <= i || i < 0) { return absl::InvalidArgumentError("Index out of range"); } - return fields[i]; + if (fields[i] == nullptr) { + return absl::InvalidArgumentError("Field not set yet."); + } + return fields[i].get(); } // TODO(Tuple) This is bad imho. Here we assume that f is allocated by the // caller and what if this is not the case? We need to be careful.. -absl::Status Tuple::SetField(int i, Field* f) { +absl::Status Tuple::SetField(int i, std::unique_ptr<Field> f) { if (fields.size() <= i || i < 0) { return absl::InvalidArgumentError("Index out of range"); } - if (fields[i]->GetType() != f->GetType()) { + if (fields[i].get() && fields[i]->GetType() != f->GetType()) { return absl::InvalidArgumentError("Fields differ in type"); } - delete fields[i]; - fields[i] = f; + + fields[i] = std::move(f); return absl::OkStatus(); } |