Skip to content

Defined in header <fkYAML/node.hpp>

fkyaml::basic_node::get_anchor_name

const std::string& get_anchor_name() const;

Gets the anchor name associated with the YAML node.
Some anchor name must be set before calling this API.
Calling has_anchor_name to see if the node has any anchor name beforehand.

Return Value

The anchor name associated to the node.
If no anchor name has been set, an fkyaml::exception will be thrown.

Example
#include <iostream>
#include <fkYAML/node.hpp>

int main() {
    // create a YAML node.
    fkyaml::node n = 123;

    // try to get an anchor name before any anchor name has been set.
    try {
        std::cout << n.get_anchor_name() << std::endl;
    }
    catch (const fkyaml::exception& e) {
        std::cout << e.what() << std::endl;
    }

    // set an anchor name to the node.
    n.add_anchor_name("anchor");
    std::cout << n.get_anchor_name() << std::endl;

    return 0;
}

output:

No anchor name has been set.
anchor

See Also