size_t UnicodeDecoder::decode(Char *to, const char *from, size_t fromLen, const char **rest) { union U { unsigned short word; char bytes[2]; }; if (subDecoder_) return subDecoder_->decode(to, from, fromLen, rest); if (fromLen < 2) { *rest = from; return 0; } minBytesPerChar_ = 2; U u; u.bytes[0] = from[0]; u.bytes[1] = from[1]; if (u.word == byteOrderMark) { hadByteOrderMark_ = 1; from += 2; fromLen -= 2; } else if (u.word == swappedByteOrderMark) { hadByteOrderMark_ = 1; from += 2; fromLen -= 2; swapBytes_ = 1; } if (hadByteOrderMark_ || !subCodingSystem_) subCodingSystem_ = new UTF16CodingSystem; subDecoder_ = subCodingSystem_->makeDecoder(swapBytes_); minBytesPerChar_ = subDecoder_->minBytesPerChar(); return subDecoder_->decode(to, from, fromLen, rest); }
/** Test eager loading of foreign keys. */ void tst_QDjangoModel::selectRelated() { // load fixtures { Item *item1 = new Item; item1->setName("first"); QCOMPARE(item1->save(), true); Item *item2 = new Item; item2->setName("second"); QCOMPARE(item2->save(), true); Owner owner; owner.setName("owner"); owner.setItem1(item1); owner.setItem2(item2); QCOMPARE(owner.save(), true); } // without eager loading QDjangoQuerySet<Owner> qs; Owner *owner = qs.get(QDjangoWhere("name", QDjangoWhere::Equals, "owner")); QVERIFY(owner != 0); QCOMPARE(owner->item1()->name(), QLatin1String("first")); QCOMPARE(owner->item2()->name(), QLatin1String("second")); delete owner; // with eager loading owner = qs.selectRelated().get(QDjangoWhere("name", QDjangoWhere::Equals, "owner")); QVERIFY(owner != 0); QCOMPARE(owner->item1()->name(), QLatin1String("first")); QCOMPARE(owner->item2()->name(), QLatin1String("second")); delete owner; }
string Owner::serialize(const Owner& owner) { Object object(true); object.set("id", owner.id()); object.set("displayName", owner.displayName()); stringstream ss; object.stringify(ss); return ss.str(); }
void UserManager::updateUser(const Owner &owner, QTreeWidgetItem *groupItem) { // qtreewidget 不能设置model,只好构造一个userTreeWidget类来更新用户 QTreeWidgetItem* item = new QTreeWidgetItem(groupItem); groupItem->addChild(item); UserItemWidget *userItemWidget = new UserItemWidget(owner.name(), owner.ip(), item, Macai::userTreeWidget); userItemWidget->setLoginName(owner.loginName()); userItemWidget->setHostName(owner.host()); userItemWidget->setUserGroup(groupItem->text(0)); Macai::userTreeWidget->setItemWidget(item, 0, userItemWidget); }
Boolean UnicodeDecoder::convertOffset(unsigned long &n) const { subDecoder_->convertOffset(n); if (hadByteOrderMark_) n += 2; return true; }
NumericCharRefOrigin::NumericCharRefOrigin(const Location &start, Index refLength, Owner<Markup> &markup) : start_(start), refLength_(refLength) { markup.swap(markup_); }
/** Perform filtering on foreign keys. */ void tst_QDjangoModel::filterRelated() { // load fixtures { Item *item1 = new Item; item1->setName("first"); QCOMPARE(item1->save(), true); Item *item2 = new Item; item2->setName("second"); QCOMPARE(item2->save(), true); Owner owner; owner.setName("owner"); owner.setItem1(item1); owner.setItem2(item2); QCOMPARE(owner.save(), true); } // perform filtering QDjangoQuerySet<Owner> owners; QDjangoQuerySet<Owner> qs = owners.filter( QDjangoWhere("item1__name", QDjangoWhere::Equals, "first")); CHECKWHERE(qs.where(), QLatin1String("T0.\"name\" = ?"), QVariantList() << "first"); QCOMPARE(qs.count(), 1); QCOMPARE(qs.size(), 1); Owner *owner = qs.at(0); QVERIFY(owner != 0); QCOMPARE(owner->name(), QLatin1String("owner")); delete owner; }
ElementDefinition::ElementDefinition(const Location &location, size_t index, unsigned char omitFlags, DeclaredContent declaredContent, Owner<CompiledModelGroup> &modelGroup) : location_(location), index_(index), omitFlags_(omitFlags), declaredContent_(declaredContent), modelGroup_(modelGroup.extract()) { computeMode(); }
void cal_test_pak_type(const Owner& owner, const test_pak_type& cdt, Runner* prunner, const Handler& handler) { std::cout << "calculate" << std::endl; svr_ptr_single_type::obj_ptr_type ptr = svr_ptr_single_type::get_ins(); if(ptr) { if(!(ptr->op_handler().get_session_mgr()->access(owner.owner_id(), boost::bind(&Calculator::print_socket_info, shared_from_this(), _1)))) { std::cout << "print_error" << std::endl; } } owner_info_container_type owners; owners.insert(owner); YGGR_PP_TASK_CENTER_BACK_TASK(handler, prunner, error_maker_type::make_error(0), yggr::task_center::runtime_task_type::E_CAL_RESULT, owners, cdt); }
void cal_test_pak_type(const Owner& owner, const test_pak_type& cdt, Runner* prunner, const Handler& handler) { //static int count = 0; static int i = 0; if(owner.size() == 1) { proxy_register_msg_type msg; /*msg.add_reg_data(test_pak_type::s_data_info(), proxy_mode_def_type::E_proxy_mode_monopolize, test_pak_type::s_cal_type());*/ msg.add_reg_data(test_pak_type::s_data_info(), now_state, test_pak_type::s_cal_type()); owner_info_container_type owners; owners.insert(owner); YGGR_PP_TASK_CENTER_BACK_TASK(handler, prunner, error_maker_type::make_error(0), yggr::task_center::runtime_task_type::E_CAL_RESULT, owners, msg); return; } ++i; std::cout << "-------------calculate " << i << "-----------------------"<< std::endl; std::cout << "id = " << cdt.id() << std::endl; owner_info_container_type owners; owners.insert(owner); YGGR_PP_TASK_CENTER_BACK_TASK(handler, prunner, error_maker_type::make_error(0), yggr::task_center::runtime_task_type::E_CAL_RESULT, owners, cdt); return; }
size_t UnicodeDecoder::decode(Char *to, const char *from, size_t fromLen, const char **rest) { union U { unsigned short word; char bytes[2]; }; if (subDecoder_) return subDecoder_->decode(to, from, fromLen, rest); if (!hadFirstChar_) { hadFirstChar_ = 1; minBytesPerChar_ = 2; if (fromLen < 2) { *rest = from; return 0; } U u; u.bytes[0] = from[0]; u.bytes[1] = from[1]; if (u.word == byteOrderMark) { hadByteOrderMark_ = 1; from += 2; fromLen -= 2; } else if (u.word == swappedByteOrderMark) { hadByteOrderMark_ = 1; from += 2; fromLen -= 2; swapBytes_ = 1; } else if (subCodingSystem_) { subDecoder_ = subCodingSystem_->makeDecoder(); minBytesPerChar_ = subDecoder_->minBytesPerChar(); return subDecoder_->decode(to, from, fromLen, rest); } } fromLen &= ~1; *rest = from + fromLen; if (sizeof(Char) == 2) { if (!swapBytes_) { if (from != (char *)to) memmove(to, from, fromLen); return fromLen/2; } } if (swapBytes_) { for (size_t n = fromLen; n > 0; n -= 2) { U u; u.bytes[1] = *from++; u.bytes[0] = *from++; *to++ = u.word; } } else { for (size_t n = fromLen; n > 0; n -= 2) { U u; u.bytes[0] = *from++; u.bytes[1] = *from++; *to++ = u.word; } } return fromLen/2; }
int main(int argc, char* argv[]) { if(!CommandLine::Instance().Parse(argc,argv)) { return -1; } try { Safir::Dob::Connection connection; SimpleDispatcher dispatcher(connection); std::wstring name = L"Entity"; if (CommandLine::Instance().Owner()) { name += L"Owner"; } else if (CommandLine::Instance().Subscriber()) { name += L"Subscriber"; } for(int instance = 0;;++instance) { try { connection.Open(name, boost::lexical_cast<std::wstring>(instance), 0, // Context &dispatcher, &dispatcher); break; } catch(const Safir::Dob::NotOpenException &) { } } std::wcout << "Started as " << Safir::Dob::ConnectionAspectMisc(connection).GetConnectionName() << std::endl; bool done = false; if (CommandLine::Instance().Owner()) { Owner owner; while (!done) { if (!CommandLine::Instance().NoSleep()) { const bool dispatch = dispatcher.Wait(CommandLine::Instance().SleepTime()); if (dispatch) { connection.Dispatch(); } } for (int i = 0; i < CommandLine::Instance().BatchSize(); ++i) { owner.Set(); } } } else if (CommandLine::Instance().Subscriber()) { Subscriber subscriber; bool started = false; while (!done) { const bool dispatch = dispatcher.Wait(10000); if(dispatch) { started = true; connection.Dispatch(); } else if (started) { std::wcout << "No dispatch event in 10s, printing statistics and exiting" << std::endl; subscriber.PrintStatistics(); if (CommandLine::Instance().ExtraDispatch()) { std::wcout << "Performing an extra dispatch, and then printing statistics again:" << std::endl; connection.Dispatch(); subscriber.PrintStatistics(); } break; } } } } catch(std::exception & e) { std::wcout << "Caught std::exception! Contents of exception is:" << std::endl << e.what()<<std::endl; std::cin.get(); } catch (...) { std::wcout << "Caught ... exception!" << std::endl; std::cin.get(); } return 0; }
void UnicodeEncoder::output(const Char *s, size_t n, OutputByteStream *sb) { subEncoder_->output(s, n, sb); }
void RendererComponent::RegisterComponent(Owner entity) { EntityComponent::RegisterComponent(entity); Engine::Instance()->GetRenderer()->AttachComponent(entity.lock(), shared_from_this()); }
/** \brief create error message. * \param where place where exception has been risen. * \param owner parameter's owner. * \param key parameter name that is not set. */ ExceptionNoSuchParameter(const Location &where, const Owner &owner, const Key &key): Exception(where, cc("no such read-only parameter: '", key.get(), "' for user '", owner.get(), "'") ) { }