uint16_t calculateParentRcv(Node_t *node, Tree_t *tree)
{
    List listChildren; memset(&listChildren, 0, sizeof(List)); ListInit(&listChildren);

    Tree_t *subTree = getSubTree(tree, node);
    getListNodesInTree(subTree, &listChildren);

    uint16_t res = 0;
    for (ListElem *elem = ListFirst(&listChildren); elem != NULL; elem = ListNext(&listChildren, elem))
    {
        Node_t *node = (Node_t *)elem->obj;
        res += node->q;
    }

    return (res);
}
bool Building::setStatus(std::string id, std::list<int>& status) {
	std::lock_guard<std::mutex> lock(buildingMutex);
	std::shared_ptr<Node> node = getNode(id);
	if (node == NULL) {
		return false;
	}
	if (node->getType() == Node::SWITCH && status.front() == 0) {
		std::list<std::shared_ptr<Node>> afterNodes = getSubTree(id);
		for (std::list<std::shared_ptr<Node>>::const_iterator iterator =
				afterNodes.begin(); iterator != afterNodes.end(); ++iterator) {
			resetNodeStatus(*iterator);
		}
	}
	node->setStatus(status);
	return true;
}
std::string Building::toDisplayString(std::string id) {
	std::string result;
	std::list<std::shared_ptr<Node>> nodes = getSubTree(id);
	unsigned int level = std::count(id.begin(), id.end(),
			FormatConst::ID_SEPERATOR); // used to track tree level
	for (std::list<std::shared_ptr<Node>>::const_iterator iterator =
			nodes.begin(); iterator != nodes.end(); ++iterator) {
		std::string id = (*iterator)->getId();
		std::string nodeData = (*iterator)->toDisplayString();
		// new line for next level
		if (std::count(id.begin(), id.end(), FormatConst::ID_SEPERATOR)
				> level) {
			result.append("\n");
			level++;
		}
		result.append(nodeData);
		result.append("\n");
	}
	return result;
}
void StandardServiceRoot::start(bool freshly_activated) {
  loadFromDatabase();

  if (freshly_activated) {
    // In other words, if there are no feeds or categories added.
    if (MessageBox::show(qApp->mainFormWidget(), QMessageBox::Question, QObject::tr("Load initial set of feeds"),
                         tr("This new account does not include any feeds. You can now add default set of feeds."),
                         tr("Do you want to load initial set of feeds?"),
                         QString(), QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {
      QString target_opml_file = APP_INITIAL_FEEDS_PATH + QDir::separator() + FEED_INITIAL_OPML_PATTERN;
      QString current_locale = qApp->localization()->loadedLanguage();
      QString file_to_load;

      if (QFile::exists(target_opml_file.arg(current_locale))) {
        file_to_load = target_opml_file.arg(current_locale);
      }
      else if (QFile::exists(target_opml_file.arg(DEFAULT_LOCALE))) {
        file_to_load = target_opml_file.arg(DEFAULT_LOCALE);
      }

      FeedsImportExportModel model;
      QString output_msg;

      try {
        model.importAsOPML20(IOFactory::readTextFile(file_to_load), false);
        model.checkAllItems();

        if (mergeImportExportModel(&model, this, output_msg)) {
          requestItemExpand(getSubTree(), true);
        }
      }
      catch (ApplicationException &ex) {
        MessageBox::show(qApp->mainFormWidget(), QMessageBox::Critical, tr("Error when loading initial feeds"), ex.message());
      }
    }
  }

  checkArgumentsForFeedAdding();
}
Beispiel #5
0
 PathTree* _navigate(const std::vector<PathElemT>& vec, size_t i) {
     if(i == vec.size()) return this;
     PathTree* next = getSubTree(vec[i]);
     if(next) return next->_navigate(vec, i+1);
     return NULL;
 }