Exemple #1
0
bool DataList::Rename(const std::string& old_name, const std::string& new_name)
{
    // check that new name is not used up.
    if (nodes.find(BA::to_lower_copy(new_name)) != nodes.end())
        return false;
    nodes_iterator i = nodes.find(BA::to_lower_copy(old_name));
    if (i == nodes.end())
        return false;
    PNode node = i->second;

    ASSERT_LOGIC(node.Ok(), "Internal TDF tree consistency (1)");
    ASSERT_LOGIC(node->Name().Lower() == old_name.Lower(), "Internal TDF tree consistency (2)");

    node->name = BA::to_lower_copy(new_name);
    nodes.erase(i);
    bool inserted = nodes.insert(std::pair<std::string, PNode>(BA::to_lower_copy(node->name), node)).second;
    ASSERT_LOGIC(inserted, "DataList::Rename failed");
    return inserted;
}