Result GraphInfo::Dump()

in cpp/src/graphar/graph_info.cc [1295:1343]


Result<std::string> GraphInfo::Dump() const {
  if (!IsValidated()) {
    return Status::Invalid("The graph info is not validated.");
  }
  ::Yaml::Node node;
  std::string dump_string;
  try {
    node["name"] = impl_->name_;
    node["prefix"] = impl_->prefix_;
    node["vertices"];
    node["edges"];
    for (const auto& vertex : GetVertexInfos()) {
      node["vertices"].PushBack();
      node["vertices"][node["vertices"].Size() - 1] =
          vertex->GetType() + ".vertex.yaml";
    }
    for (const auto& edge : GetEdgeInfos()) {
      node["edges"].PushBack();
      node["edges"][node["edges"].Size() - 1] =
          ConcatEdgeTriple(edge->GetSrcType(), edge->GetEdgeType(),
                           edge->GetDstType()) +
          ".edge.yaml";
    }
    if (impl_->labels_.size() > 0) {
      node["labels"];
      for (const auto& label : impl_->labels_) {
        node["labels"].PushBack();
        node["labels"][node["labels"].Size() - 1] = label;
      }
    }
    if (impl_->version_ != nullptr) {
      node["version"] = impl_->version_->ToString();
    }
    if (impl_->extra_info_.size() > 0) {
      node["extra_info"];
      for (const auto& pair : impl_->extra_info_) {
        ::Yaml::Node extra_info_node;
        extra_info_node["key"] = pair.first;
        extra_info_node["value"] = pair.second;
        node["extra_info"].PushBack();
        node["extra_info"][node["extra_info"].Size() - 1] = extra_info_node;
      }
    }
    ::Yaml::Serialize(node, dump_string);
  } catch (const std::exception& e) {
    return Status::Invalid("Failed to dump graph info: ", e.what());
  }
  return dump_string;
}