Esempio n. 1
0
QVariant NewsFeedModel::data(const QModelIndex &index, int role) const
{
    int row = index.row();

    auto news = m_newsList.at(row);
    switch (role) {
    case TypeRole:
        return news.type();
    case PostIdRole:
        return news.postId();
        break;
    case SourceRole: {
        int source = news.sourceId();
        return qVariantFromValue(findContact(source));
    }
    case DateRole:
        return news.date();
    case BodyRole:
        return news.body();
    case AttachmentsRole:
        return vk::Attachment::toVariantMap(news.attachments());
    case LikesRole:
        return news.likes();
    case RepostsRole:
        return news.reposts();
    case CommentsRole:
        return news.property("comments");
    case OwnerNameRole: {
        int ownerId = news.property("copy_owner_id").toInt();
        if (ownerId) {
            auto contact = findContact(ownerId);
            return contact->name();
        }
        return QVariant();
    }
    case SourcePhotoRole: {
        if (auto contact = findContact(news.sourceId()))
            return contact->photoSource();
        break;
    }
    case SourceNameRole: {
        if (auto contact = findContact(news.sourceId()))
            return contact->name();
        break;
    }
    case LikesCount: {
        return news.likes().value("count").toInt();
    }
    case CommentsCount:
        return news.property("comments").toMap().value("count").toInt();
    default:
        break;
    }
    return QVariant::Invalid;
}
Esempio n. 2
0
File: cfg.cpp Progetto: Yermo/hhvm
/*
 * Find the immediate dominator of each block using Cooper, Harvey, and
 * Kennedy's "A Simple, Fast Dominance Algorithm", returned as a vector
 * of Block*, indexed by block.  IdomVector[b] == nullptr if b has no
 * dominator.  This is the case for the entry block and any blocks not
 * reachable from the entry block.
 */
IdomVector findDominators(const IRUnit& unit, const BlockList& blocks) {
  assert(isRPOSorted(blocks));

  // Calculate immediate dominators with the iterative two-finger algorithm.
  // When it terminates, idom[post-id] will contain the post-id of the
  // immediate dominator of each block.  idom[start] will be -1.  This is
  // the general algorithm but it will only loop twice for loop-free graphs.
  IdomVector idom(unit, nullptr);
  auto start = blocks.begin();
  auto entry = *start;
  idom[entry] = entry;
  start++;
  for (bool changed = true; changed; ) {
    changed = false;
    // for each block after start, in reverse postorder
    for (auto it = start; it != blocks.end(); it++) {
      Block* block = *it;
      // p1 = any already-processed predecessor
      auto predIter = block->preds().begin();
      auto predEnd = block->preds().end();
      auto p1 = predIter->from();
      while (!idom[p1]) p1 = (++predIter)->from();
      // for all other already-processed predecessors p2 of block
      for (++predIter; predIter != predEnd; ++predIter) {
        auto p2 = predIter->from();
        if (p2 == p1 || !idom[p2]) continue;
        // find earliest common predecessor of p1 and p2
        // (higher postIds are earlier in flow and in dom-tree).
        do {
          while (p1->postId() < p2->postId()) p1 = idom[p1];
          while (p2->postId() < p1->postId()) p2 = idom[p2];
        } while (p1 != p2);
      }
      if (idom[block] != p1) {
        idom[block] = p1;
        changed = true;
      }
    }
  }
  idom[entry] = nullptr; // entry has no dominator.
  return idom;
}
Esempio n. 3
0
File: Id.cpp Progetto: OSLL/scblog
  bool CId::operator==(const CId& obj) const
  {
   /* return (((!obj.ssId().isEmpty()) && (obj.ssId() == ssId()))
        || ((!obj.ljId().isEmpty()) && (obj.ljId() == ljId())));
*/
    bool isSSIds = ((!obj.ssId().isEmpty()) && (obj.ssId() == ssId()));
    bool isEqualsPCIds = (((!obj.ljId().isEmpty()) && (obj.ljId() == obj.postId())) || ((!ljId().isEmpty()) && (ljId() == postId())));
    bool fullEqualsLjId = ((obj.ljId() == ljId()) && (obj.postId() == postId()));
    bool notFullEquals = ((!obj.ljId().isEmpty()) && (obj.ljId() == ljId()));

    if (isSSIds)
      return true;

    if (isEqualsPCIds)
      return fullEqualsLjId;

    return notFullEquals;
  }
Esempio n. 4
0
HippoBSTR 
HippoExplorerBar::getFramerUrl(const HippoBSTR &pageUrl)
{
    // We look at the toplevel URL of the page (it should be /visit?post=<postId>)
    // to figure out what URL we want to navigate to

    HippoURLParser parser(pageUrl);
    if (!parser.ok())
        return NULL;

    if (parser.getScheme() != INTERNET_SCHEME_HTTP)
        return NULL;
    
    if (!hippoIsOurServer(parser.getHostName()))
        return NULL;

    HippoBSTR urlPath = parser.getUrlPath();
    if (!urlPath || wcscmp(urlPath.m_str, L"/visit") != 0)
        return NULL;

    HippoBSTR extraInfo = parser.getExtraInfo();
    if (!extraInfo || wcsncmp(extraInfo.m_str, L"?post=", 6) != 0)
        return NULL;

    HippoBSTR postId(extraInfo.m_str + 6);
    if (!hippoVerifyGuid(postId))
        return NULL;

    HippoBSTR framerUrl(L"http://");
    framerUrl.Append(parser.getHostName());
    if (parser.getPort() != 80) {
        WCHAR buf[32];
        StringCchPrintf(buf, sizeof(buf) / sizeof(buf[0]), L":%d", parser.getPort());
        framerUrl.Append(buf);
    }
    framerUrl.Append(L"/framer?browserBar=true&postId=");
    framerUrl.Append(postId);

    return framerUrl;
}