Exemple #1
0
unsigned
Store::child_name_offset(const Raul::Path&   parent,
                         const Raul::Symbol& symbol,
                         bool                allow_zero) const
{
	unsigned offset = 0;

	while (true) {
		std::stringstream ss;
		ss << symbol;
		if (offset > 0) {
			ss << "_" << offset;
		}
		if (find(parent.child(Raul::Symbol(ss.str()))) == end() &&
		    (allow_zero || offset > 0)) {
			break;
		} else if (offset == 0) {
			offset = 2;
		} else {
			++offset;
		}
	}

	return offset;
}
Exemple #2
0
void
Store::rename(const iterator top, const Raul::Path& new_path)
{
	const Raul::Path old_path = top->first;

	// Remove the object and all its descendants
	Objects removed;
	remove(top, removed);

	// Rename all the removed objects
	for (Objects::const_iterator i = removed.begin(); i != removed.end(); ++i) {
		const Raul::Path path = (i->first == old_path)
			? new_path
			: new_path.child(
				Raul::Path(i->first.substr(old_path.base().length() - 1)));

		i->second->set_path(path);
		assert(find(path) == end());  // Shouldn't be dropping objects!
		insert(make_pair(path, i->second));
	}
}