Skip to content

Commit

Permalink
Provide yaml_encode for datatype_t
Browse files Browse the repository at this point in the history
  • Loading branch information
eschnett committed May 25, 2018
1 parent 743330f commit 07c3d15
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
12 changes: 10 additions & 2 deletions asdf_datatype.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,12 @@ class field_t {

field_t(const reader_state &rs, const YAML::Node &node);
field_t(const copy_state &cs, const field_t &field);
YAML::Node to_yaml(writer &w) const;
YAML::Node to_yaml() const;
YAML::Node to_yaml(writer &w) const { return to_yaml(); }
};

inline YAML::Node yaml_encode(const field_t &field) { return field.to_yaml(); }

class datatype_t {
public:
bool is_scalar;
Expand All @@ -207,11 +210,16 @@ class datatype_t {

datatype_t(const reader_state &rs, const YAML::Node &node);
datatype_t(const copy_state &cs, const datatype_t &datatype);
YAML::Node to_yaml(writer &w) const;
YAML::Node to_yaml() const;
YAML::Node to_yaml(writer &w) const { return to_yaml(); }

size_t type_size() const;
};

inline YAML::Node yaml_encode(const datatype_t &datatype) {
return datatype.to_yaml();
}

void parse_scalar(const YAML::Node &node, unsigned char *data,
const shared_ptr<datatype_t> &datatype,
byteorder_t byteorder = host_byteorder());
Expand Down
8 changes: 4 additions & 4 deletions datatype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -431,11 +431,11 @@ field_t::field_t(const reader_state &rs, const YAML::Node &node) { assert(0); }

field_t::field_t(const copy_state &cs, const field_t &field) { assert(0); }

YAML::Node field_t::to_yaml(writer &w) const {
YAML::Node field_t::to_yaml() const {
YAML::Node node;
if (!name.empty())
node["name"] = name;
node["datatype"] = datatype->to_yaml(w);
node["datatype"] = datatype->to_yaml();
if (have_byteorder)
node["byteorder"] = yaml_encode(byteorder);
if (!shape.empty())
Expand Down Expand Up @@ -478,12 +478,12 @@ datatype_t::datatype_t(const copy_state &cs, const datatype_t &datatype) {
assert(0);
}

YAML::Node datatype_t::to_yaml(writer &w) const {
YAML::Node datatype_t::to_yaml() const {
if (is_scalar)
return yaml_encode(scalar_type_id);
YAML::Node node;
for (const auto &field : fields)
node.push_back(field->to_yaml(w));
node.push_back(field->to_yaml());
return node;
}

Expand Down

0 comments on commit 07c3d15

Please sign in to comment.