Example #1
0
std::vector<Record*> Datastore::_recordsOnPath(const std::vector<std::string>& path) {

	if (path.empty()) { return {}; } // invalid path

	std::vector<Record*> ret;

	Record* r = &_root;

	for (auto&& token : path) {
		try {
			r = &r->getChild(token.c_str());
		} catch (...) {
			ret.insert(ret.end(), path.size() - ret.size(), nullptr); // fill remainder with null
			return ret;
		}
		ret.push_back(r);
	}
	return ret;
}
Example #2
0
Record* Datastore::getRecord(const std::string& path) {

	// TODO: string operations like this are expensive, optimize?
	auto tokens = _tokenizePath(path);
	if (tokens.empty()) { return nullptr; } // invalid path

	Record* r = &_root;

	try {
		for (auto&& token : tokens) {
			r = &r->getChild(token.c_str());
			if (r->getType() == RecordType::kUndefined) {
				return nullptr;
			}
		}
	} catch (...) {
		return nullptr;
	}
	return r;
}