blob: 3e937d3df8afac4fa22b57a0144048e78036e25b [file] [log] [blame]
// Copyright 2018 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "fidl/attributes.h"
namespace fidl {
bool AttributesBuilder::Insert(std::unique_ptr<raw::Attribute> attribute) {
auto attribute_name = attribute->name;
auto attribute_location = attribute->location();
auto result = InsertHelper(std::move(attribute));
switch (result.kind) {
case InsertResult::Kind::kDuplicate: {
std::string message("duplicate attribute with name '");
message.append(attribute_name);
message.append("'");
error_reporter_->ReportError(attribute_location, message);
return false;
}
case InsertResult::Kind::kOk:
return true;
} // switch
}
std::vector<std::unique_ptr<raw::Attribute>> AttributesBuilder::Done() {
return std::move(attributes_);
}
AttributesBuilder::InsertResult AttributesBuilder::InsertHelper(std::unique_ptr<raw::Attribute> attribute) {
if (!names_.emplace(attribute->name).second) {
return InsertResult(InsertResult::kDuplicate, "");
}
auto attribute_name = attribute->name;
auto attribute_value = attribute->value;
attributes_.push_back(std::move(attribute));
return InsertResult(InsertResult::kOk, "");
}
} // namespace fidl