void set_path(const Raul::Path& path) { remove(); const char* text = (path.is_root()) ? "/" : path.symbol(); Gtk::Label* lab = manage(new Gtk::Label(text)); lab->set_padding(0, 0); lab->show(); add(*lab); if (_view && _view->graph()->path() != path) _view.reset(); }
void ObjectModel::set_path(const Raul::Path& p) { _path = p; _symbol = p.symbol(); INGEN_EMIT_THIS(moved); }
ObjectModel::ObjectModel(Shared::LV2URIMap& uris, const Raul::Path& path) : ResourceImpl(uris, path) , _meta(uris, Raul::URI("http://example.org/FIXME")) , _path(path) , _symbol((path == Path::root()) ? "root" : path.symbol()) { }
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; }
/** Rename */ virtual void set_path(const Raul::Path& new_path) { _path = new_path; const char* const new_sym = new_path.symbol(); if (new_sym[0] != '\0') { _symbol = Raul::Symbol(new_sym); } set_uri(Node::path_to_uri(new_path)); }
void JackDriver::rename_port(const Raul::Path& old_path, const Raul::Path& new_path) { EnginePort* eport = get_port(old_path); if (eport) { jack_port_set_name((jack_port_t*)eport->handle(), new_path.substr(1).c_str()); } }
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)); } }
unsigned Store::child_name_offset(const Raul::Path& parent, const Raul::Symbol& symbol, bool allow_zero) { unsigned offset = 0; while (true) { std::stringstream ss; ss << symbol; if (offset > 0) ss << "_" << offset; if (find(parent.base() + ss.str()) == end() && (allow_zero || offset > 0)) break; else if (offset == 0) offset = 2; else ++offset; } return offset; }
const Raul::Path ClashAvoider::map_path(const Raul::Path& in) { unsigned offset = 0; bool has_offset = false; const size_t pos = in.find_last_of('_'); if (pos != string::npos && pos != (in.length()-1)) { const std::string trailing = in.substr(pos + 1); has_offset = (sscanf(trailing.c_str(), "%u", &offset) > 0); } // Path without _n suffix std::string base_path_str = in; if (has_offset) { base_path_str = base_path_str.substr(0, base_path_str.find_last_of('_')); } Raul::Path base_path(base_path_str); SymbolMap::iterator m = _symbol_map.find(in); if (m != _symbol_map.end()) { return m->second; } else { typedef std::pair<SymbolMap::iterator, bool> InsertRecord; // See if parent is mapped Raul::Path parent = in.parent(); do { SymbolMap::iterator p = _symbol_map.find(parent); if (p != _symbol_map.end()) { const Raul::Path mapped = Raul::Path( p->second.base() + in.substr(parent.base().length())); InsertRecord i = _symbol_map.insert(make_pair(in, mapped)); return i.first->second; } parent = parent.parent(); } while (!parent.is_root()); if (!exists(in) && _symbol_map.find(in) == _symbol_map.end()) { // No clash, use symbol unmodified InsertRecord i = _symbol_map.insert(make_pair(in, in)); assert(i.second); return i.first->second; } else { // Append _2 _3 etc until an unused symbol is found while (true) { Offsets::iterator o = _offsets.find(base_path); if (o != _offsets.end()) { offset = ++o->second; } else { string parent_str = in.parent().base(); parent_str = parent_str.substr(0, parent_str.find_last_of("/")); if (parent_str.empty()) parent_str = "/"; } if (offset == 0) offset = 2; std::stringstream ss; ss << base_path << "_" << offset; if (!exists(Raul::Path(ss.str()))) { std::string name = base_path.symbol(); if (name == "") name = "_"; Raul::Symbol sym(name); string str = ss.str(); InsertRecord i = _symbol_map.insert( make_pair(in, Raul::Path(str))); offset = _store.child_name_offset(in.parent(), sym, false); _offsets.insert(make_pair(base_path, offset)); return i.first->second; } else { if (o != _offsets.end()) offset = ++o->second; else ++offset; } } } } }
static Raul::URI path_to_uri(const Raul::Path& path) { return Raul::URI(root_uri() + path.c_str()); }