std::list<LedgerEntry>::const_iterator LedgerStateRoot::Impl::loadOffers(StatementContext& prep, std::list<LedgerEntry>& offers) const { std::string actIDStrKey; unsigned int sellingAssetType, buyingAssetType; std::string sellingAssetCode, buyingAssetCode, sellingIssuerStrKey, buyingIssuerStrKey; soci::indicator sellingAssetCodeIndicator, buyingAssetCodeIndicator, sellingIssuerIndicator, buyingIssuerIndicator; LedgerEntry le; le.data.type(OFFER); OfferEntry& oe = le.data.offer(); auto& st = prep.statement(); st.exchange(soci::into(actIDStrKey)); st.exchange(soci::into(oe.offerID)); st.exchange(soci::into(sellingAssetType)); st.exchange(soci::into(sellingAssetCode, sellingAssetCodeIndicator)); st.exchange(soci::into(sellingIssuerStrKey, sellingIssuerIndicator)); st.exchange(soci::into(buyingAssetType)); st.exchange(soci::into(buyingAssetCode, buyingAssetCodeIndicator)); st.exchange(soci::into(buyingIssuerStrKey, buyingIssuerIndicator)); st.exchange(soci::into(oe.amount)); st.exchange(soci::into(oe.price.n)); st.exchange(soci::into(oe.price.d)); st.exchange(soci::into(oe.flags)); st.exchange(soci::into(le.lastModifiedLedgerSeq)); st.define_and_bind(); st.execute(true); auto iterNext = offers.cend(); while (st.got_data()) { oe.sellerID = KeyUtils::fromStrKey<PublicKey>(actIDStrKey); processAsset(oe.selling, (AssetType)sellingAssetType, sellingIssuerStrKey, sellingIssuerIndicator, sellingAssetCode, sellingAssetCodeIndicator); processAsset(oe.buying, (AssetType)buyingAssetType, buyingIssuerStrKey, buyingIssuerIndicator, buyingAssetCode, buyingAssetCodeIndicator); if (iterNext == offers.cend()) { iterNext = offers.emplace(iterNext, le); } else { offers.emplace_back(le); } st.fetch(); } return iterNext; }
void emplace_front(Args&&... args) { const bool need_reinit = (min_ == data_.cend()); data_.emplace_front(std::forward<Args>(args)...); if (need_reinit || data_.front() < *min_) { min_ = pointer_to_first(); } }
void ContactList::initContacts(const std::list<ContactGroup> &contactGroups) { for(auto it = contactGroups.cbegin(); it != contactGroups.cend(); ++it) { const ContactGroup &group = *it; auto groupName = group.name; Wt::WPanel * panel = new Wt::WPanel; panel->setTitle(groupName); panel->setCollapsible(true); panel->setCentralWidget(new Wt::WContainerWidget()); mContactPanels.insert(std::make_pair(group,panel)); for(auto contactIt = group.contacts.cbegin(); contactIt != group.contacts.cend(); ++contactIt) { const ContactInfo &info = *contactIt; addContact(info.uin,info.showName); mContacts.push_back(info); } } showFullList(); }
bool Map::CanMoveTo(const GameObject* movingObject, const Rectangle& position, const std::list<GameObject*>& objects) const { if (IsInMapBounds(position) == false) return false; const MapCell* cell = GetCellFromRealPosition(position.Left(), position.Top()); if (cell->GetIsObstacle() == true) return false; cell = GetCellFromRealPosition(position.Right() - 1, position.Top()); if (cell->GetIsObstacle() == true) return false; cell = GetCellFromRealPosition(position.Left(), position.Bottom() - 1); if (cell->GetIsObstacle() == true) return false; cell = GetCellFromRealPosition(position.Right() - 1, position.Bottom() - 1); if (cell->GetIsObstacle() == true) return false; for (std::list<GameObject*>::const_iterator it = objects.cbegin(); it != objects.cend(); ++it) { if ((*it != movingObject) && ((*it)->IsCollidable() == true) && (*it)->IsCollidingWith(position) == true) return false; } return true; }
void Harness::onMessages(const std::list<omx_message> &messages) { Mutex::Autolock autoLock(mLock); for (std::list<omx_message>::const_iterator it = messages.cbegin(); it != messages.cend(); ) { mMessageQueue.push_back(*it++); } mMessageAddedCondition.signal(); }
/// \b Complexity: amort O(1) void pop_back() { const bool need_reinit = (min_ == pointer_to_last()); data_.pop_back(); if (need_reinit) { min_ = std::min_element(data_.cbegin(), data_.cend()); } }
void print_list(std::list<int> list, const char *key_string) { std::cout << key_string << std::endl; for (auto it = list.cbegin(); it != list.cend(); it++) { std::cout << *it; } std::cout << std::endl; }
queue_with_min& operator=(const queue_with_min& q) { if (this == &q) { return *this; } data_ = q.data_; min_ = std::min_element(data_.cbegin(), data_.cend()); return *this; }
std::list<std::string> StatementPrinter::generateStatementLines(const std::list<Transaction>& transactions) { std::list<std::string> statementLines; for (auto it = transactions.cbegin(); it != transactions.cend(); ++it) { this->runningBalance += it->amount(); statementLines.push_back(generateStatementLine(*it)); } return statementLines; }
/** * Common function for command service callbacks. * * NOTE: success is bool in messages, but has unsigned char type in C++ */ bool send_command_long_and_wait(uint16_t command, uint8_t confirmation, float param1, float param2, float param3, float param4, float param5, float param6, float param7, unsigned char &success, uint8_t &result) { unique_lock lock(mutex); /* check transactions */ for (auto it = ack_waiting_list.cbegin(); it != ack_waiting_list.cend(); it++) if ((*it)->expected_command == command) { ROS_WARN_THROTTLE_NAMED(10, "cmd", "Command %u alredy in progress", command); return false; } //! @note APM always send COMMAND_ACK, while PX4 never. bool is_ack_required = (confirmation != 0 || uas->is_ardupilotmega()) && !uas->is_px4(); if (is_ack_required) ack_waiting_list.push_back(new CommandTransaction(command)); command_long(command, confirmation, param1, param2, param3, param4, param5, param6, param7); if (is_ack_required) { auto it = ack_waiting_list.begin(); for (; it != ack_waiting_list.end(); it++) if ((*it)->expected_command == command) break; if (it == ack_waiting_list.end()) { ROS_ERROR_NAMED("cmd", "CommandTransaction not found for %u", command); return false; } lock.unlock(); bool is_not_timeout = wait_ack_for(*it); lock.lock(); success = is_not_timeout && (*it)->result == MAV_RESULT_ACCEPTED; result = (*it)->result; delete *it; ack_waiting_list.erase(it); } else { success = true; result = MAV_RESULT_ACCEPTED; } return true; }
QuadNode::QuadNode(int id, int x, int y, int width, int height, std::list<NodeObject*> listNodeObject) { _id = id; _bouding._x = x; _bouding._y = y; _bouding._w = width; _bouding._h = height; std::move(listNodeObject.cbegin(), listNodeObject.cend(), std::back_inserter(_listNodeObject)); }
void ChatroomFrontpage::OnUserInfoChange(const std::list<nim::UserNameCard> &uinfos) { for (auto iter = uinfos.cbegin(); iter != uinfos.cend(); iter++) { if (nim_ui::LoginManager::GetInstance()->IsEqual(iter->GetAccId())) { InitHeader(); break; } } }
void AutoMagic::installAutoMagic(SeparatistaDocument *pDocument) { DEBUG_STATIC_METHOD; typedef struct { void (*pfnCreateAutoMagicFactory)(SeparatistaDocument *pDocument, const wchar_t *pBasePath, const wchar_t *pWatchPath, const wchar_t *pValuePath); const wchar_t *pBasePath; const wchar_t *pWatchPath; const wchar_t *pValuePath; } AutoMagicInfo; // Insert new automagic here std::unordered_map<std::wstring, const std::initializer_list<AutoMagicInfo>> autoMagicMap = { { Separatista::camt_053_001_02::Namespace, { // Order is important here, value elements being watched should be created last } }, { Separatista::pain_001_001_03::Namespace, { // Order is important here, value elements being watched should be created last } }, { Separatista::pain_008_001_02::Namespace, { // Order is important here, value elements being watched should be created last { AutoMagicFactory<SumAutoMagic>::Create, TEXT("CstmrDrctDbtInitn"), TEXT("PmtInf/NbOfTxs"), TEXT("GrpHdr/NbOfTxs") }, { AutoMagicFactory<SumAutoMagic>::Create, TEXT("CstmrDrctDbtInitn"), TEXT("PmtInf/CtrlSum"), TEXT("GrpHdr/CtrlSum") }, { AutoMagicFactory<CountAutoMagic>::Create, TEXT("CstmrDrctDbtInitn/PmtInf"), TEXT("DrctDbtTxInf"), TEXT("NbOfTxs") }, { AutoMagicFactory<SumAutoMagic>::Create, TEXT("CstmrDrctDbtInitn/PmtInf"), TEXT("DrctDbtTxInf/InstdAmt"), TEXT("CtrlSum") } } } }; const std::list<AutoMagicInfo> infoList = autoMagicMap[pDocument->getNamespaceURI()]; for (auto info = infoList.cbegin(); info != infoList.cend(); info++) { info->pfnCreateAutoMagicFactory(pDocument, info->pBasePath, info->pWatchPath, info->pValuePath); } }
void handle_command_ack(const mavlink::mavlink_message_t *msg, mavlink::common::msg::COMMAND_ACK &ack) { lock_guard lock(mutex); for (auto it = ack_waiting_list.cbegin(); it != ack_waiting_list.cend(); it++) if ((*it)->expected_command == ack.command) { (*it)->result = ack.result; (*it)->ack.notify_all(); return; } ROS_WARN_THROTTLE_NAMED(10, "cmd", "CMD: Unexpected command %u, result %u", ack.command, ack.result); }
bool Explosion::CanExplode(const Rectangle& zone, std::list<GameObject*>& objects, const Map& map, bool& block) { block = false; if (map.IsInMapBounds(zone) == false) return false; for (std::list<GameObject*>::const_iterator it = objects.cbegin(); it != objects.cend(); ++it) { if ((*it)->IsCollidingWith(zone) == true) { return (*it)->CanExplode(block); } } return true; }
int compare(std::vector<int> &vi, std::list<int> &li) { int ret = 0; auto i = vi.cbegin(); auto j = li.cbegin(); for (; i != vi.cend() && j != li.cend(); i++, j++) { if (*i > *j) { ret = 1; break; } else if (*i < *j) { ret = -1; break; } } if (ret != 0) return ret; else if (i != vi.cend()) return 1; else if (j != li.cend()) return -1; else return 0; }
void handle_command_ack(const mavlink_message_t *msg, uint8_t sysid, uint8_t compid) { mavlink_command_ack_t ack; mavlink_msg_command_ack_decode(msg, &ack); lock_guard lock(mutex); for (auto it = ack_waiting_list.cbegin(); it != ack_waiting_list.cend(); it++) if ((*it)->expected_command == ack.command) { (*it)->result = ack.result; (*it)->ack.notify_all(); return; } ROS_WARN_THROTTLE_NAMED(10, "cmd", "CMD: Unexpected command %u, result %u", ack.command, ack.result); }
bool User::GetUserNameCardOnline(const std::list<std::string>& accids, const GetUserNameCardCallback& cb, const std::string& json_extension /*= ""*/) { if (accids.empty()) return false; GetUserNameCardCallback* cb_pointer = nullptr; if (cb) { cb_pointer = new GetUserNameCardCallback(cb); } Json::Value values; for (auto iter = accids.cbegin(); iter != accids.cend(); ++iter) values.append(*iter); NIM_SDK_GET_FUNC(nim_user_get_user_name_card_online)(values.toStyledString().c_str(), json_extension.c_str(), &CallbackGetUserNameCard, cb_pointer); return true; }
bool compareAdjVertices(const std::list<Edge>& adj, const std::list<int>& adjVert, int vertexToExclude) { bool result = true; std::list<int>::const_iterator adjVertIt = adjVert.cbegin(); for (std::list<Edge>::const_iterator adjit = adj.cbegin(); adjit != adj.cend() && adjVertIt != adjVert.cend(); ++adjit, ++adjVertIt) { auto w = adjit->other(vertexToExclude); auto v = *adjVertIt; if (w == v) continue; result = false; break; } return result; }
std::size_t CsvInterface::findColumn(std::string const& line, char delim, std::string const& column_name) { std::list<std::string> const fields = BaseLib::splitString(line, delim); if (fields.empty()) return std::numeric_limits<std::size_t>::max(); std::size_t count(0); for (auto it = fields.cbegin(); it != fields.cend(); ++it) { if ((*it).compare(column_name) == 0) break; else count++; } if (count == fields.size()) return std::numeric_limits<std::size_t>::max(); return count; }
iter search(const std::list<int> & li, const int num) { static iter sp = li.cbegin(); // last time found const static iter iter_end = li.cend(); if(sp == iter_end) sp = li.cbegin(); while(*sp != num && sp != iter_end) { if(*sp > num) { --sp; if(*sp < num) sp = iter_end; } else { ++sp; if(*sp > num) sp = iter_end; }//if-else }//while return sp; }//search
bool DiaBinarySaver::saveEnities(LPCTSTR lpszPathName, const std::list<DiaEntity*>& entities) const { std::fstream file(lpszPathName, std::ios_base::out|std::ios_base::binary); for (std::list<DiaEntity*>::const_iterator it = entities.cbegin() ; it != entities.cend(); it++) { const DiaEntity* e = *it; DiaEntity::Type type = e->type(); switch (type) { case DiaEntity::Ellipse : { saveEllipse(e, file); break; } case DiaEntity::Rectangle : { saveRectangle(e, file); break; } case DiaEntity::Triangle : { saveTriangle(e, file); break; } case DiaEntity::Arrow : { saveArrow(e, file); break; } default: break; } } file.close(); return true; }
void printl(std::list<int> &li) { for (auto i = li.cbegin(); i != li.cend(); i++) std::cout << *i << " "; }
queue_with_min& operator=(std::initializer_list<value_type> il) { data_ = il; min_ = std::min_element(data_.cbegin(), data_.cend()); return *this; }
queue_with_min(const queue_with_min& q) : data_(q.data_) , min_( std::min_element(data_.cbegin(), data_.cend()) ) {}
/// \b Complexity: O(1) queue_with_min() noexcept : data_() , min_(data_.cend()) {}
/// \b Complexity: O(N), in case of POD type up to O(1) void clear() noexcept { data_.clear(); min_ = data_.cend(); }
bool IGFrame::ManageSelection (const IGLibrary::SELECTIONPARAMS& selParams, const std::list<POINT>& lPts) { // Request thread access if (!RequestAccess ()) return false; CxImage *pCurrentLayer = GetWorkingLayer(); if (!pCurrentLayer) return false; int nCurLayerId = (int)pCurrentLayer->GetId(); int nCurLayerWidth = (int)pCurrentLayer->GetWidth(); int nCurLayerHeight = (int)pCurrentLayer->GetHeight(); _ASSERTE ((nCurLayerId >= 0) && L"Current layer is not identified"); if (nCurLayerId < 0) return false; bool bRes = false; POINT ptTopLeft = {0, 0}; POINT ptBottomRight = {-1, -1}; IGSELECTIONENUM eSelectionType = selParams.eSelectionType; if (((eSelectionType & IGSELECTION_SQUARE) == IGSELECTION_SQUARE) || ((eSelectionType & IGSELECTION_LASSO) == IGSELECTION_LASSO)) { if (lPts.size() > 0) { bool bAllEqual = true; for (list <POINT>::const_iterator itPt = lPts.cbegin(); itPt != lPts.cend(); ++itPt) { if (((*itPt).x != lPts.front().x) || ((*itPt).y != lPts.front().y)) bAllEqual = false; } if (bAllEqual) eSelectionType = IGSELECTION_CLEAR; } } if ((eSelectionType & IGSELECTION_CLEAR) == IGSELECTION_CLEAR) { if ((eSelectionType & IGSELECTION_INVERT) == IGSELECTION_INVERT) bRes = pCurrentLayer->SelectionInvert(); else bRes = pCurrentLayer->SelectionDelete(); } else { if ((eSelectionType & IGSELECTION_REPLACE) == IGSELECTION_REPLACE) pCurrentLayer->SelectionClear(); BYTE level = ((eSelectionType & IGSELECTION_REMOVE) == IGSELECTION_REMOVE) ? 0 : 255; std::list<POINT> lConvertedPts (lPts); // convert IG coordinates to Cx coordinates IGConvertible::FromIGtoCxCoords(lConvertedPts, pCurrentLayer->GetHeight()); // apply selection if ((eSelectionType & IGSELECTION_SQUARE) == IGSELECTION_SQUARE) { if (lPts.size() != 2) return false; // read rectangle coordinates ptTopLeft = lConvertedPts.front(); ptBottomRight = lConvertedPts.back(); int nPosX = ptTopLeft.x; int nPosY = ptBottomRight.y; RECT rcSel; rcSel.left = nPosX; rcSel.top = nPosY; nPosX = ptBottomRight.x; nPosY = ptTopLeft.y; rcSel.right = nPosX; rcSel.bottom = nPosY; // adjust rectangle orientation int nWidth = rcSel.right - rcSel.left; int nHeight = rcSel.top - rcSel.bottom; nWidth = (nWidth < 0) ? -1 * nWidth : nWidth; nHeight = (nHeight < 0) ? -1 * nHeight : nHeight; rcSel.left = (rcSel.left < rcSel.right) ? rcSel.left : rcSel.right; rcSel.bottom = (rcSel.bottom < rcSel.top) ? rcSel.bottom : rcSel.top; rcSel.right = rcSel.left + nWidth; rcSel.top = rcSel.bottom + nHeight; // test if rectangle is inside the frame if ((rcSel.right < 0) || (rcSel.left >= nCurLayerWidth) || (rcSel.top < 0) || (rcSel.bottom >= nCurLayerHeight)) return false; // selection out of bounds // adjust bounds rcSel.left = (rcSel.left < 0) ? 0 : rcSel.left; rcSel.right = (rcSel.right >= nCurLayerWidth) ? nCurLayerWidth - 1 : rcSel.right; rcSel.bottom = (rcSel.bottom < 0) ? 0 : rcSel.bottom; rcSel.top = (rcSel.top >= nCurLayerHeight) ? nCurLayerHeight - 1 : rcSel.top; // add the selection bRes = pCurrentLayer->SelectionAddRect (rcSel, level); } else if ((eSelectionType & IGSELECTION_LASSO) == IGSELECTION_LASSO) { bRes = pCurrentLayer->SelectionAddPolygon (lConvertedPts, level); } else if ((eSelectionType & IGSELECTION_MAGIC) == IGSELECTION_MAGIC) { bRes = pCurrentLayer->SelectionAddMagic (lConvertedPts.front(), level, selParams.nTolerance); } else if ((eSelectionType & IGSELECTION_FACES) == IGSELECTION_FACES) { bRes = pCurrentLayer->SelectionAddFaces (level); } else if ((eSelectionType & IGSELECTION_EYES) == IGSELECTION_EYES) { bRes = pCurrentLayer->SelectionAddEyes (level); } else if ((eSelectionType & IGSELECTION_MOUTH) == IGSELECTION_MOUTH) { bRes = pCurrentLayer->SelectionAddMouth (level); } else if ((eSelectionType & IGSELECTION_NOZE) == IGSELECTION_NOZE) { bRes = pCurrentLayer->SelectionAddNoze (level); } else if ((eSelectionType & IGSELECTION_LPE) == IGSELECTION_LPE) { bRes = pCurrentLayer->SelectionAddLPE (lConvertedPts, level); } if (ptBottomRight.x < ptTopLeft.x) { int nSwap = ptTopLeft.x; ptTopLeft.x = ptBottomRight.x; ptBottomRight.x = nSwap; } if (ptBottomRight.y < ptTopLeft.y) { int nSwap = ptTopLeft.y; ptTopLeft.y = ptBottomRight.y; ptBottomRight.y = nSwap; } if (ptTopLeft.x < 0) ptTopLeft.x = 0; if (ptTopLeft.y < 0) ptTopLeft.y = 0; if (ptBottomRight.x >= nCurLayerWidth) ptBottomRight.x = nCurLayerWidth - 1; if (ptBottomRight.y >= nCurLayerHeight) ptBottomRight.y = nCurLayerHeight - 1; } if (!pCurrentLayer->SelectionIsValid()) pCurrentLayer->SelectionDelete(); AddNewStep (IGFRAMEHISTORY_STEP_SELECTION, L"Change selection", (int)&selParams, (int)&lPts); Redraw (true); return bRes; }
queue_with_min(std::initializer_list<value_type> il) : data_(il) , min_( std::min_element(data_.cbegin(), data_.cend()) ) {}
std::wstring CRealTextParser::RenderTags(const std::list<Tag>& p_crlTags) { bool bEmpty(true); std::wstring szString; for (auto iter = p_crlTags.cbegin(); iter != p_crlTags.cend(); ++iter) { Tag oTag(*iter); if (oTag.m_szName == L"br") { szString += L"\n"; } else if (oTag.m_szName == L"b") { if (!m_bIgnoreFontWeight) { if (oTag.m_bOpen) { szString += L"<b>"; } else if (oTag.m_bClose) { szString += L"</b>"; } } } else if (oTag.m_szName == L"i") { if (!m_bIgnoreFontWeight) { if (oTag.m_bOpen) { szString += L"<i>"; } else if (oTag.m_bClose) { szString += L"</i>"; } } } else if (oTag.m_szName == L"font") { if (!m_bIgnoreFont) { if (oTag.m_bOpen) { szString += L"<font"; for (std::map<std::wstring, std::wstring>:: iterator i = oTag.m_mapAttributes.begin(); i != oTag.m_mapAttributes.end(); ++i) { if (m_bIgnoreFontSize && i->first == L"size") { continue; } if (m_bIgnoreFontColor && i->first == L"color") { continue; } if (m_bIgnoreFontFace && i->first == L"face") { continue; } if (i->first == L"size" && !i->second.empty() && ::iswdigit(i->second.at(0))) { int iSize = ::_wtoi(i->second.c_str()); if (iSize > 0 && iSize < m_iMinFontSize) { continue; } if (iSize > m_iMaxFontSize) { continue; } } szString += L" "; szString += i->first; szString += L"=\""; szString += i->second; szString += L"\""; } szString += L">"; } if (oTag.m_bClose) { szString += L"</font>"; } } } else if (oTag.m_bText) { szString += oTag.m_szName; if (!oTag.m_szName.empty()) { bEmpty = false; } } else { //AfxMessageBox(CString(_T("Unknown RealText-tag: ")) + oTag.m_szName.c_str()); } } if (bEmpty) { return L""; } else { return szString; } }