void TerrainSample::initialize() { // Load scene _scene = Scene::load("res/common/terrain/sample.scene"); _terrain = dynamic_cast<Terrain*>(_scene->findNode("terrain")->getDrawable()); _sky = _scene->findNode("sky"); _sky->setTag("lighting", "none"); // Load shapes Bundle* bundle; bundle = Bundle::create("res/common/sphere.gpb"); _sphere = bundle->loadNode("sphere"); dynamic_cast<Model*>(_sphere->getDrawable())->setMaterial("res/common/terrain/shapes.material#sphere", 0); SAFE_RELEASE(bundle); bundle = Bundle::create("res/common/box.gpb"); _box = bundle->loadNode("box"); dynamic_cast<Model*>(_box->getDrawable())->setMaterial("res/common/terrain/shapes.material#box", 0); SAFE_RELEASE(bundle); // Load font _font = Font::create("res/ui/arial.gpb"); // Setup form _form = Form::create("res/common/terrain/terrain.form"); _form->getControl("plusButton")->addListener(this, Control::Listener::CLICK); _form->getControl("minusButton")->addListener(this, Control::Listener::CLICK); _form->getControl("wireframe")->addListener(this, Control::Listener::VALUE_CHANGED); _form->getControl("patches")->addListener(this, Control::Listener::VALUE_CHANGED); _form->getControl("physics")->addListener(this, Control::Listener::VALUE_CHANGED); _form->getControl("lod")->addListener(this, Control::Listener::VALUE_CHANGED); _form->getControl("culling")->addListener(this, Control::Listener::VALUE_CHANGED); _form->getControl("snapToGround")->addListener(this, Control::Listener::VALUE_CHANGED); _form->getControl("dropSphere")->addListener(this, Control::Listener::CLICK); _form->getControl("dropBox")->addListener(this, Control::Listener::CLICK); _form->getControl("clearAll")->addListener(this, Control::Listener::CLICK); Control* main = _form->getControl("main"); _formSize.set(main->getWidth(), main->getHeight()); // Use script camera for navigation enableScriptCamera(true); setScriptCameraSpeed(20, 80); _directionalLight = _scene->findNode("directionalLight")->getLight(); }
void receive(std::size_t sid, Args&&... args) const { curr_val_[sid] = value_type(args...); if (curr_val_.size() != bundle_->lpipes_count()) { return; } argument_type container; std::for_each( std::make_move_iterator(std::begin(curr_val_)), std::make_move_iterator(std::end(curr_val_)), [&container](auto&& pair) { container.push_back(std::move(pair.second)); }); curr_val_.clear(); bundle_->send(bundle_->invoke(std::move(container))); }
virtual void onExport(iwriter & writer) { writer.putUnsignedInt(_bundle.numCols()); writer.put(_counter); writer.putBool(_eachStep); writer.putString(_label); writer.put(_onlySample); }
// Set drawing style of secondary surface bool Commands::function_GridStyleSecondary(CommandNode* c, Bundle& obj, ReturnValue& rv) { if (obj.notifyNull(Bundle::GridPointer)) return false; Grid::SurfaceStyle ss = Grid::surfaceStyle(c->argc(0)); if (ss == Grid::nSurfaceStyles) return false; obj.g->setSecondaryStyle(ss); rv.reset(); return true; }
/** * Send a bundle to check it with the wireshark. * The bundle must be valid. * It will appears under UDP. */ TEST(BundleTest, WiresharkTest) { Bundle b = Bundle("node100", "node101", "This is a test payload"); std::string raw = b.toRaw(); sockaddr_in remote = { 0 }; remote.sin_family = AF_INET; remote.sin_port = htons(0); remote.sin_addr.s_addr = htonl(INADDR_ANY); int sock = socket(AF_INET, SOCK_DGRAM, 0); EXPECT_LE(0, bind(sock, reinterpret_cast<sockaddr*>(&remote), sizeof(remote))); sockaddr_in destination = { 0 }; destination.sin_family = AF_INET; destination.sin_port = htons(4556); inet_aton("127.0.0.1", &destination.sin_addr); EXPECT_LT( 0, sendto(sock, raw.c_str(), raw.size(), 0, reinterpret_cast<sockaddr*>(&destination), sizeof(destination))); }
void Audio3DTest::initialize() { setMultiTouch(true); _font = Font::create("res/common/arial18.gpb"); // Load game scene from file Bundle* bundle = Bundle::create("res/common/box.gpb"); _scene = bundle->loadScene(); SAFE_RELEASE(bundle); // Get light node Node* lightNode = _scene->findNode("directionalLight1"); Light* light = lightNode->getLight(); // Initialize box model Node* boxNode = _scene->findNode("box"); Model* boxModel = boxNode->getModel(); Material* boxMaterial = boxModel->setMaterial("res/common/box.material"); boxMaterial->getParameter("u_lightColor")->setValue(light->getColor()); boxMaterial->getParameter("u_lightDirection")->setValue(lightNode->getForwardVectorView()); // Remove the cube from the scene but keep a reference to it. _cubeNode = boxNode; _cubeNode->addRef(); _scene->removeNode(_cubeNode); loadGrid(_scene); // Initialize cameraa Vector3 cameraPosition(5, 5, 1); if (Camera* camera = _scene->getActiveCamera()) { camera->getNode()->getTranslation(&cameraPosition); } _fpCamera.initialize(); _fpCamera.setPosition(cameraPosition); _scene->addNode(_fpCamera.getRootNode()); _scene->setActiveCamera(_fpCamera.getCamera()); _gamepad = getGamepad(0); GP_ASSERT(_gamepad); _gamepad->getForm()->setConsumeInputEvents(false); }
ATEN_USING_NAMESPACE // Add free grid point data at specified coordinates bool Commands::function_AddFreePoint(CommandNode* c, Bundle& obj, ReturnValue& rv) { if (obj.notifyNull(Bundle::GridPointer)) return false; obj.g->addFreePoint(c->argd(0), c->argd(1), c->argd(2), c->argd(3)); rv.reset(); return true; }
void SpaceshipGame::initialize() { // TODO: Not working on iOS // Display the gameplay splash screen for at least 1 second. displayScreen(this, &SpaceshipGame::drawSplash, NULL, 1000L); // Create our render state block that will be reused across all materials _stateBlock = RenderState::StateBlock::create(); _stateBlock->setDepthTest(true); _stateBlock->setCullFace(true); _stateBlock->setBlend(true); _stateBlock->setBlendSrc(RenderState::BLEND_SRC_ALPHA); _stateBlock->setBlendDst(RenderState::BLEND_ONE_MINUS_SRC_ALPHA); // Load our scene from file Bundle* bundle = Bundle::create("res/spaceship.gpb"); _scene = bundle->loadScene(); SAFE_RELEASE(bundle); // Update the aspect ratio for our scene's camera to match the current device resolution _scene->getActiveCamera()->setAspectRatio((float)getWidth() / (float)getHeight()); // Initialize scene data initializeSpaceship(); initializeEnvironment(); // Create a background audio track _backgroundSound = AudioSource::create("res/background.ogg"); if (_backgroundSound) _backgroundSound->setLooped(true); // Create font _font = Font::create("res/airstrip28.gpb"); // Store camera node _cameraNode = _scene->findNode("camera1"); // Store initial ship and camera positions _initialShipPos = _shipGroupNode->getTranslation(); _initialShipRot = _shipGroupNode->getRotation(); _initialCameraPos = _cameraNode->getTranslation(); }
// Set grid axes (nine doubles) bool Commands::function_GridAxes(CommandNode* c, Bundle& obj, ReturnValue& rv) { if (obj.notifyNull(Bundle::GridPointer)) return false; Matrix mat; mat.setColumn(0, c->arg3d(0), 0.0); mat.setColumn(1, c->arg3d(3), 0.0); mat.setColumn(2, c->arg3d(6), 0.0); obj.g->setAxes(mat); rv.reset(); return true; }
// Return nth grid of model bool Commands::function_GetGrid(CommandNode* c, Bundle& obj, ReturnValue& rv) { if (obj.notifyNull(Bundle::ModelPointer)) return false; Grid* g = NULL; switch (c->argType(0)) { case (VTypes::IntegerData): g = obj.rs()->grid(c->argi(0)-1); break; case (VTypes::GridData): g = (Grid*) c->argp(0, VTypes::GridData); break; default: Messenger::print("Can't convert a variable of type '%s' to a Grid.", VTypes::dataType(c->argType(0))); break; } if (g == NULL) return false; rv.set(VTypes::GridData, g); return true; }
void FightPrepare::fight() { if (mState != Prepare_State_Loaded) { CCAssert(false,"数据还没准备好,请确认调用了prepareData函数载入数据,并且是在prepareSuccess回调接口中调用的这个函数"); return; } Bundle bundle; bundle.putBool("testMode",mTestMode); if (!mTestMode) { bundle.putString("JumpToWhenEnd","FightEndLayer"); } // 直接换scene ClientFightLayer* layer = (ClientFightLayer*)GameDirector::getDirector()->fight(mPreparedDir_vec,mCallback->getBg(mTaskId,mGridIndex),bundle); GameDirector::getDirector()->hideWaiting(); layer->setBeforeFightPro(beforeFightPro); }
/** * Check the raw functions when a canonical block is added. * Generate a bundle, add a valid canonical block, convert all to raw. * Create a new bundle from that raw, check that all the blocks are correct. */ TEST(BundleTest, ConstructorWithCanonical) { Bundle b = Bundle("Source", "Destination", "This is a payload"); std::stringstream ss; // Block Type ss << static_cast<uint8_t>(2) << SDNV::encode(std::bitset<7>().to_ulong()); std::string data = std::to_string(rand() + 1); ss << SDNV::encode(data.size()) << data; std::shared_ptr<CanonicalBlock> cb = std::shared_ptr<CanonicalBlock>( new CanonicalBlock(ss.str())); ASSERT_EQ(ss.str(), cb->toRaw()); b.addBlock(cb); ASSERT_EQ(static_cast<uint8_t>(3), b.getBlocks().size()); std::string raw = b.toRaw(); Bundle b1 = Bundle(raw); ASSERT_EQ(b.getBlocks().size(), b1.getBlocks().size()); std::shared_ptr<CanonicalBlock> cb1 = std::static_pointer_cast<CanonicalBlock>(b1.getBlocks()[2]); ASSERT_EQ(cb->toRaw(), cb1->toRaw()); ASSERT_EQ(cb->getBlockType(), cb1->getBlockType()); }
void OMEMO::publishOwnBundle(int account) { Bundle b = getSignal(account)->collectBundle(); if (!b.isValid()) return; QDomDocument doc; QDomElement publish = doc.createElement("publish"); doc.appendChild(publish); QDomElement item = doc.createElement("item"); publish.appendChild(item); QDomElement bundle = doc.createElementNS(OMEMO_XMLNS, "bundle"); item.appendChild(bundle); publish.setAttribute("node", bundleNodeName(getSignal(account)->getDeviceId())); QDomElement signedPreKey = doc.createElement("signedPreKeyPublic"); signedPreKey.setAttribute("signedPreKeyId", b.signedPreKeyId); setNodeText(signedPreKey, b.signedPreKeyPublic); bundle.appendChild(signedPreKey); QDomElement signedPreKeySignature = doc.createElement("signedPreKeySignature"); setNodeText(signedPreKeySignature, b.signedPreKeySignature); bundle.appendChild(signedPreKeySignature); QDomElement identityKey = doc.createElement("identityKey"); setNodeText(identityKey, b.identityKeyPublic); bundle.appendChild(identityKey); QDomElement preKeys = doc.createElement("prekeys"); bundle.appendChild(preKeys); foreach (auto preKey, b.preKeys) { QDomElement preKeyPublic = doc.createElement("preKeyPublic"); preKeyPublic.setAttribute("preKeyId", preKey.first); setNodeText(preKeyPublic, preKey.second); preKeys.appendChild(preKeyPublic); } pepPublish(account, doc.toString()); }
//------------------------------------------------------------------------------------- Reason WebSocketPacketFilter::send(Channel * pChannel, PacketSender& sender, Packet * pPacket) { Bundle* pBundle = pPacket->pBundle(); TCPPacket* pRetTCPPacket = TCPPacket::ObjPool().createObject(); websocket::WebSocketProtocol::FrameType frameType = websocket::WebSocketProtocol::BINARY_FRAME; if(pBundle && pBundle->packets().size() > 1) { bool isEnd = pBundle->packets().back() == pPacket; bool isBegin = pBundle->packets().front() == pPacket; if(!isEnd && !isBegin) { frameType = websocket::WebSocketProtocol::NEXT_FRAME; } else { if(!isEnd) frameType = websocket::WebSocketProtocol::INCOMPLETE_BINARY_FRAME; else frameType = websocket::WebSocketProtocol::END_FRAME; } } websocket::WebSocketProtocol::makeFrame(frameType, pPacket, pRetTCPPacket); int space = pPacket->length() - pRetTCPPacket->space(); if(space > 0) { WARNING_MSG(fmt::format("WebSocketPacketFilter::send: no free space, buffer added:{}, total={}.\n", space, pRetTCPPacket->size())); pRetTCPPacket->data_resize(pRetTCPPacket->size() + space); } (*pRetTCPPacket).append(pPacket->data() + pPacket->rpos(), pPacket->length()); pRetTCPPacket->swap(*(static_cast<KBEngine::MemoryStream*>(pPacket))); TCPPacket::ObjPool().reclaimObject(pRetTCPPacket); return PacketFilter::send(pChannel, sender, pPacket); }
pointer us_bundle_stop(scheme* sc, pointer args) { if(args == sc->NIL) { std::cerr << "Empty argument list" << std::endl; return sc->F; } if (sc->vptr->list_length(sc, args) != 1) { return sc->F; } pointer arg = pair_car(args); Bundle bundle; if (is_string(arg)) { std::string name = sc->vptr->string_value(arg); bundle = get_bundle(name); } else if (is_integer(arg)) { bundle = GetBundleContext().GetBundle(ivalue(arg)); } if (bundle) { try { bundle.Stop(); return sc->T; } catch (const std::exception& e) { std::cerr << e.what(); } } return sc->F; }
bool Layer_list_model::import_from_bundle(Bundle& bundle) { unsigned n = bundle.size(); for (unsigned i = 0; i < n && i < layers.size(); i++) { unsigned layer_index = 0; QString layer_name = bundle.layer_name(i); QByteArray layer_state = bundle.layer_state(i); while (layer_index < layers.size() && layer_name != layers[layer_index]->get_name()) { layer_index++; } if (layer_index==layers.size()) continue; swap_in_layers(i, layer_index); #ifdef INVALIDATE_CACHE_AT_COLOR_CHANGE layers[i]->invalidate_cache();/// \todo why do I need this for colors? it should work without invalidating with the display lists #endif layers[i]->restoreState(bundle.layer_state(i)); } // deactivate for (unsigned i=0; i < layers.size(); i++) { bool found = false; QString name_from_layers = layers[i]->get_name(); for (int j=0; j<bundle.size(); j++) if (name_from_layers == bundle.layer_name(j)) found = true; if (!found) layers[i]->set_active(false); } filter_apply(filter_text, show_only_active); emit dataChanged(QModelIndex(), QModelIndex()); emit layers_reordered(); return true; }
// Set colour scale for grid bool Commands::function_GridColourscale(CommandNode* c, Bundle& obj, ReturnValue& rv) { if (obj.notifyNull(Bundle::GridPointer)) return false; int cs = c->argi(0); if ((cs < 0) || (cs > 10)) { Messenger::print("ColourScale %i is out of range (1-10, or 0 to use object's internal colour).",cs); return false; } obj.g->setColourScale(cs-1); rv.reset(); return true; }
template<class Obs, class Bundle> double cost(const Bundle& bundle) { const auto nb_obs = bundle.template at_obs<Obs>().size(); if (nb_obs==0) return 0; // std::cout << " cost without save " << std::endl; double total = 0; // #pragma omp parallel for reduction(+:total) if(use_omp()) for(auto iobs = bundle.template at_obs<Obs>().first() ; iobs < nb_obs ; ++iobs) { //total += (make_function(bundle.obs(iobs))(bundle.map(iobs))).squaredNorm() / 2; auto pair_residu = make_function(bundle.obs(iobs))(bundle.map(iobs)); if (pair_residu.second) total += ( pair_residu ).first.squaredNorm(); } if (std::isnan(total)) throw NAN_ERROR(" NAN : cost_and_save"); return total/2.0; }
void EchoWorker::callbackBundleReceived(const Bundle &b) { try { const PayloadBlock &payload = b.find<PayloadBlock>(); // generate a echo Bundle echo; // make a copy of the payload block ibrcommon::BLOB::Reference ref = payload.getBLOB(); echo.push_back(ref); // set destination and mark the bundle as singleton destination echo.destination = b.source; echo.set(dtn::data::PrimaryBlock::DESTINATION_IS_SINGLETON, true); // set the source of the bundle echo.source = getWorkerURI(); // set the lifetime to the same value as the received bundle echo.lifetime = b.lifetime; try { const dtn::data::TrackingBlock &tracking = b.find<dtn::data::TrackingBlock>(); dtn::data::TrackingBlock &target = echo.push_back<dtn::data::TrackingBlock>(); // copy tracking block target = tracking; } catch (const dtn::data::Bundle::NoSuchBlockFoundException&) { }; IBRCOMMON_LOGGER_DEBUG_TAG("EchoWorker", 5) << "echo request received, replying!" << IBRCOMMON_LOGGER_ENDL; // send it transmit( echo ); } catch (const dtn::data::Bundle::NoSuchBlockFoundException&) { } }
static int lua_Bundle_contains(lua_State* state) { // Get the number of parameters. int paramCount = lua_gettop(state); // Attempt to match the parameters to a valid binding. switch (paramCount) { case 2: { if ((lua_type(state, 1) == LUA_TUSERDATA) && (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL)) { // Get parameter 1 off the stack. const char* param1 = gameplay::ScriptUtil::getString(2, false); Bundle* instance = getInstance(state); bool result = instance->contains(param1); // Push the return value onto the stack. lua_pushboolean(state, result); return 1; } lua_pushstring(state, "lua_Bundle_contains - Failed to match the given parameters to a valid function signature."); lua_error(state); break; } default: { lua_pushstring(state, "Invalid number of parameters (expected 2)."); lua_error(state); break; } } return 0; }
static int lua_Bundle_getObjectId(lua_State* state) { // Get the number of parameters. int paramCount = lua_gettop(state); // Attempt to match the parameters to a valid binding. switch (paramCount) { case 2: { if ((lua_type(state, 1) == LUA_TUSERDATA) && lua_type(state, 2) == LUA_TNUMBER) { // Get parameter 1 off the stack. unsigned int param1 = (unsigned int)luaL_checkunsigned(state, 2); Bundle* instance = getInstance(state); const char* result = instance->getObjectId(param1); // Push the return value onto the stack. lua_pushstring(state, result); return 1; } lua_pushstring(state, "lua_Bundle_getObjectId - Failed to match the given parameters to a valid function signature."); lua_error(state); break; } default: { lua_pushstring(state, "Invalid number of parameters (expected 2)."); lua_error(state); break; } } return 0; }
// Set loop order to use in 'gridnextpoint' bool Commands::function_GridLoopOrder(CommandNode* c, Bundle& obj, ReturnValue& rv) { if (obj.notifyNull(Bundle::GridPointer)) return false; if (c->argc(0).length() != 3) { Messenger::print("A string of three characters must be passed to 'gridLoopOrder' (got '%s').", qPrintable(c->argc(0))); return false; } obj.g->setLoopOrder(c->argc(0)); rv.reset(); return true; }
void TemplateGame::initialize() { // Load game scene from file Bundle* bundle = Bundle::create("res/box.gpb"); _scene = bundle->loadScene(); SAFE_RELEASE(bundle); // Set the aspect ratio for the scene's camera to match the current resolution _scene->getActiveCamera()->setAspectRatio((float)getWidth() / (float)getHeight()); // Get light node Node* lightNode = _scene->findNode("directionalLight"); Light* light = lightNode->getLight(); // Initialize box model Node* boxNode = _scene->findNode("box"); Model* boxModel = boxNode->getModel(); Material* boxMaterial = boxModel->setMaterial("res/box.material"); boxMaterial->getParameter("u_ambientColor")->setValue(_scene->getAmbientColor()); boxMaterial->getParameter("u_ambientColor")->setValue(_scene->getAmbientColor()); boxMaterial->getParameter("u_lightColor")->setValue(light->getColor()); boxMaterial->getParameter("u_lightDirection")->setValue(lightNode->getForwardVectorView()); }
TEST(BundleTest, GetFrameworkExtension) { Bundle b = Bundle("Source", "Destination", "This is a payload"); uint8_t fwkId = 1; std::map<uint8_t, std::shared_ptr<FrameworkExtension>> extensions; nlohmann::json state = {"source", "me"}; uint8_t fwkExtId = 2; std::string code = "code"; std::shared_ptr<FrameworkExtension> ext = std::shared_ptr<FrameworkExtension>( new FrameworkExtension(fwkExtId, code)); extensions.insert(std::pair<uint8_t, std::shared_ptr<FrameworkExtension>> (fwkExtId, ext)); std::shared_ptr<FrameworkMEB> fmeb = std::shared_ptr<FrameworkMEB>(new FrameworkMEB(fwkId, extensions, state)); b.addBlock(fmeb); std::shared_ptr<FrameworkExtension> fe = b.getFwkExt(fwkId, fwkExtId); ASSERT_EQ(fe->getCodeLength(), static_cast<uint16_t>(code.length())); ASSERT_EQ(fe->getFwkExtId(), fwkExtId); ASSERT_EQ(fe->getSwSrcCode(), code); Bundle b2 = Bundle("Source", "Destination", "This is a payload"); ASSERT_THROW(b2.getFwkExt(fwkId, fwkExtId), FrameworkNotFoundException); b2.addBlock(fmeb); uint8_t fwkId2 = 3; uint8_t fwkExtId2 = 4; ASSERT_THROW(b2.getFwkExt(fwkId, fwkExtId2), FrameworkNotFoundException); ASSERT_THROW(b2.getFwkExt(fwkId2, fwkExtId), FrameworkNotFoundException); ASSERT_THROW(b2.getFwkExt(fwkId2, fwkExtId2), FrameworkNotFoundException); }
/** * Check the raw constructor. * Generate a bundle, convert it to raw, and generate a new bundle from that * raw. * The blocks must be the same. */ TEST(BundleTest, RawFunctions) { Bundle b = Bundle("Source", "Destination", "This is a payload"); std::string raw = b.toRaw(); Bundle b1 = Bundle(raw); ASSERT_EQ(b.getPrimaryBlock()->getSource(), b1.getPrimaryBlock()->getSource()); ASSERT_EQ(b.getPrimaryBlock()->getDestination(), b1.getPrimaryBlock()->getDestination()); ASSERT_EQ(b.getBlocks().size(), b1.getBlocks().size()); ASSERT_EQ( std::static_pointer_cast<CanonicalBlock>(b.getBlocks()[1])->getBlockType(), std::static_pointer_cast<CanonicalBlock>(b1.getBlocks()[1])->getBlockType()); std::shared_ptr<CanonicalBlock> PB = std::static_pointer_cast<CanonicalBlock>( b.getBlocks()[1]); std::shared_ptr<CanonicalBlock> PB1 = std::static_pointer_cast<CanonicalBlock>(b1.getBlocks()[1]); ASSERT_EQ(std::static_pointer_cast<PayloadBlock>(PB)->getPayload(), std::static_pointer_cast<PayloadBlock>(PB1)->getPayload()); }
TEST(PHPSessionSerializer, Deserialize) { std::string sessiondata = "bool|b:0;string|s:5:\"Hallo\";classobject|O:8:\"stdClass\":1:{s:8:\"property\";s:5:\"value\";}array|a:1:{i:0;s:5:\"hallo\";}null|N;integer|i:1;double|d:10;"; Bundle res = Serialize::PHPSessionSerializer().deserialize(sessiondata).as<Bundle>(); ASSERT_TRUE(res.isSet("bool")); ASSERT_TRUE(res.isSet("string")); ASSERT_TRUE(res.isSet("classobject")); ASSERT_TRUE(res.isSet("array")); ASSERT_TRUE(res.isSet("null")); ASSERT_TRUE(res.isSet("integer")); ASSERT_TRUE(res.isSet("double")); ASSERT_TRUE(res["bool"].isType<bool>()); ASSERT_TRUE(res["string"].isType<std::string>()); ASSERT_TRUE(res["classobject"].isType<Bundle>()); ASSERT_TRUE(res["array"].isType<Bundle>()); ASSERT_TRUE(res["null"].isType<nullptr_t>()); ASSERT_TRUE(res["integer"].isType<int64_t>()); ASSERT_TRUE(res["double"].isType<double>()); ASSERT_EQ(false, res["bool"].as<bool>()); ASSERT_EQ("Hallo", res["string"].as<std::string>()); ASSERT_EQ(1, res["integer"].as<int64_t>()); ASSERT_EQ(10, res["double"].as<double>()); { auto c = res["classobject"].as<Bundle>(); ASSERT_TRUE(c.isSet("property")); ASSERT_TRUE(c["property"].isType<std::string>()); ASSERT_EQ("value", c["property"].as<std::string>()); } { auto c = res["array"].as<Bundle>(); ASSERT_TRUE(c.isSet("0")); ASSERT_TRUE(c["0"].isType<std::string>()); ASSERT_EQ("hallo", c["0"].as<std::string>()); } }
ATEN_USING_NAMESPACE // Assign charge to selected atoms in model ('charge <q>'), or get charge of current selection bool Commands::function_Charge(CommandNode* c, Bundle& obj, ReturnValue& rv) { if (obj.notifyNull(Bundle::ModelPointer)) return false; double q = 0.0; if (c->hasArg(0)) { obj.rs()->beginUndoState("Charge selected atoms"); for (RefListItem<Atom,int>* ri = obj.rs()->selection(); ri != NULL; ri = ri->next) obj.rs()->atomSetCharge(ri->item, c->argd(0)); obj.rs()->endUndoState(); } else { q = 0.0; for (RefListItem<Atom,int>* ri = obj.rs()->selection(); ri != NULL; ri = ri->next) q += ri->item->charge(); } rv.set(q); return true; }
void publish_story() { LOGV("publish_story enter"); Session *session = Session::getActiveSession(); Bundle *postParams = new Bundle(); postParams->putString(to_string("name"), to_string("Facebook SDK for Android")); postParams->putString(to_string("caption"), to_string("Build great social apps and get more installs.")); postParams->putString(to_string("description"), to_string("The Facebook SDK for Android makes it easier and faster to develop Facebook integrated Android apps.")); postParams->putString(to_string("link"), to_string("https://developers.facebook.com/android")); postParams->putString(to_string("picture"), to_string("https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png")); Request *request = new Request(*session, to_string("me/feed"), *postParams, com_facebook_HttpMethod::POST, *requestCallback); std::vector<Request*> requests; requests.push_back(request); RequestAsyncTask *task = new RequestAsyncTask(requests); std::vector<Object*> *args = 0; task->execute(*args); delete task; delete request; delete postParams; delete session; LOGV("publish_story exit"); }
/* * Parse args. */ int main(int argc, char* const argv[]) { char *prog = argv[0]; Bundle bundle; bool wantUsage = false; int result = 1; // pessimistically assume an error. int tolerance = 0; /* default to compression */ bundle.setCompressionMethod(ZipEntry::kCompressDeflated); if (argc < 2) { wantUsage = true; goto bail; } if (argv[1][0] == 'v') bundle.setCommand(kCommandVersion); else if (argv[1][0] == 'd') bundle.setCommand(kCommandDump); else if (argv[1][0] == 'l') bundle.setCommand(kCommandList); else if (argv[1][0] == 'a') bundle.setCommand(kCommandAdd); else if (argv[1][0] == 'r') bundle.setCommand(kCommandRemove); else if (argv[1][0] == 'p') bundle.setCommand(kCommandPackage); else if (argv[1][0] == 'c') bundle.setCommand(kCommandCrunch); else { fprintf(stderr, "ERROR: Unknown command '%s'\n", argv[1]); wantUsage = true; goto bail; } argc -= 2; argv += 2; /* * Pull out flags. We support "-fv" and "-f -v". */ while (argc && argv[0][0] == '-') { /* flag(s) found */ const char* cp = argv[0] +1; while (*cp != '\0') { switch (*cp) { case 'v': bundle.setVerbose(true); break; case 'a': bundle.setAndroidList(true); break; case 'c': argc--; argv++; if (!argc) { fprintf(stderr, "ERROR: No argument supplied for '-c' option\n"); wantUsage = true; goto bail; } bundle.addConfigurations(argv[0]); break; case 'f': bundle.setForce(true); break; case 'g': argc--; argv++; if (!argc) { fprintf(stderr, "ERROR: No argument supplied for '-g' option\n"); wantUsage = true; goto bail; } tolerance = atoi(argv[0]); bundle.setGrayscaleTolerance(tolerance); printf("%s: Images with deviation <= %d will be forced to grayscale.\n", prog, tolerance); break; case 'k': bundle.setJunkPath(true); break; case 'm': bundle.setMakePackageDirs(true); break; case 'o': bundle.setIsOverlayPackage(true); break; #if 0 case 'p': bundle.setPseudolocalize(true); break; #endif case 'u': bundle.setUpdate(true); break; case 'x': bundle.setExtending(true); break; case 'z': bundle.setRequireLocalization(true); break; case 'j': argc--; argv++; if (!argc) { fprintf(stderr, "ERROR: No argument supplied for '-j' option\n"); wantUsage = true; goto bail; } convertPath(argv[0]); bundle.addJarFile(argv[0]); break; case 'A': argc--; argv++; if (!argc) { fprintf(stderr, "ERROR: No argument supplied for '-A' option\n"); wantUsage = true; goto bail; } convertPath(argv[0]); bundle.setAssetSourceDir(argv[0]); break; case 'G': argc--; argv++; if (!argc) { fprintf(stderr, "ERROR: No argument supplied for '-G' option\n"); wantUsage = true; goto bail; } convertPath(argv[0]); bundle.setProguardFile(argv[0]); break; case 'I': argc--; argv++; if (!argc) { fprintf(stderr, "ERROR: No argument supplied for '-I' option\n"); wantUsage = true; goto bail; } convertPath(argv[0]); bundle.addPackageInclude(argv[0]); break; case 'F': argc--; argv++; if (!argc) { fprintf(stderr, "ERROR: No argument supplied for '-F' option\n"); wantUsage = true; goto bail; } convertPath(argv[0]); bundle.setOutputAPKFile(argv[0]); break; case 'J': argc--; argv++; if (!argc) { fprintf(stderr, "ERROR: No argument supplied for '-J' option\n"); wantUsage = true; goto bail; } convertPath(argv[0]); bundle.setRClassDir(argv[0]); break; case 'M': argc--; argv++; if (!argc) { fprintf(stderr, "ERROR: No argument supplied for '-M' option\n"); wantUsage = true; goto bail; } convertPath(argv[0]); bundle.setAndroidManifestFile(argv[0]); break; case 'P': argc--; argv++; if (!argc) { fprintf(stderr, "ERROR: No argument supplied for '-P' option\n"); wantUsage = true; goto bail; } convertPath(argv[0]); bundle.setPublicOutputFile(argv[0]); break; case 'S': argc--; argv++; if (!argc) { fprintf(stderr, "ERROR: No argument supplied for '-S' option\n"); wantUsage = true; goto bail; } convertPath(argv[0]); bundle.addResourceSourceDir(argv[0]); break; case 'C': argc--; argv++; if (!argc) { fprintf(stderr, "ERROR: No argument supplied for '-C' option\n"); wantUsage = true; goto bail; } convertPath(argv[0]); bundle.setCrunchedOutputDir(argv[0]); break; case '0': argc--; argv++; if (!argc) { fprintf(stderr, "ERROR: No argument supplied for '-e' option\n"); wantUsage = true; goto bail; } if (argv[0][0] != 0) { bundle.addNoCompressExtension(argv[0]); } else { bundle.setCompressionMethod(ZipEntry::kCompressStored); } break; case '-': if (strcmp(cp, "-debug-mode") == 0) { bundle.setDebugMode(true); } else if (strcmp(cp, "-min-sdk-version") == 0) { argc--; argv++; if (!argc) { fprintf(stderr, "ERROR: No argument supplied for '--min-sdk-version' option\n"); wantUsage = true; goto bail; } bundle.setMinSdkVersion(argv[0]); } else if (strcmp(cp, "-target-sdk-version") == 0) { argc--; argv++; if (!argc) { fprintf(stderr, "ERROR: No argument supplied for '--target-sdk-version' option\n"); wantUsage = true; goto bail; } bundle.setTargetSdkVersion(argv[0]); } else if (strcmp(cp, "-max-sdk-version") == 0) { argc--; argv++; if (!argc) { fprintf(stderr, "ERROR: No argument supplied for '--max-sdk-version' option\n"); wantUsage = true; goto bail; } bundle.setMaxSdkVersion(argv[0]); } else if (strcmp(cp, "-max-res-version") == 0) { argc--; argv++; if (!argc) { fprintf(stderr, "ERROR: No argument supplied for '--max-res-version' option\n"); wantUsage = true; goto bail; } bundle.setMaxResVersion(argv[0]); } else if (strcmp(cp, "-version-code") == 0) { argc--; argv++; if (!argc) { fprintf(stderr, "ERROR: No argument supplied for '--version-code' option\n"); wantUsage = true; goto bail; } bundle.setVersionCode(argv[0]); } else if (strcmp(cp, "-version-name") == 0) { argc--; argv++; if (!argc) { fprintf(stderr, "ERROR: No argument supplied for '--version-name' option\n"); wantUsage = true; goto bail; } bundle.setVersionName(argv[0]); } else if (strcmp(cp, "-values") == 0) { bundle.setValues(true); } else if (strcmp(cp, "-custom-package") == 0) { argc--; argv++; if (!argc) { fprintf(stderr, "ERROR: No argument supplied for '--custom-package' option\n"); wantUsage = true; goto bail; } bundle.setCustomPackage(argv[0]); } else if (strcmp(cp, "-extra-packages") == 0) { argc--; argv++; if (!argc) { fprintf(stderr, "ERROR: No argument supplied for '--extra-packages' option\n"); wantUsage = true; goto bail; } bundle.setExtraPackages(argv[0]); } else if (strcmp(cp, "-generate-dependencies") == 0) { bundle.setGenDependencies(true); } else if (strcmp(cp, "-utf16") == 0) { bundle.setWantUTF16(true); } else if (strcmp(cp, "-preferred-configurations") == 0) { argc--; argv++; if (!argc) { fprintf(stderr, "ERROR: No argument supplied for '--preferred-configurations' option\n"); wantUsage = true; goto bail; } bundle.addPreferredConfigurations(argv[0]); } else if (strcmp(cp, "-rename-manifest-package") == 0) { argc--; argv++; if (!argc) { fprintf(stderr, "ERROR: No argument supplied for '--rename-manifest-package' option\n"); wantUsage = true; goto bail; } bundle.setManifestPackageNameOverride(argv[0]); } else if (strcmp(cp, "-rename-instrumentation-target-package") == 0) { argc--; argv++; if (!argc) { fprintf(stderr, "ERROR: No argument supplied for '--rename-instrumentation-target-package' option\n"); wantUsage = true; goto bail; } bundle.setInstrumentationPackageNameOverride(argv[0]); } else if (strcmp(cp, "-auto-add-overlay") == 0) { bundle.setAutoAddOverlay(true); } else if (strcmp(cp, "-product") == 0) { argc--; argv++; if (!argc) { fprintf(stderr, "ERROR: No argument supplied for '--product' option\n"); wantUsage = true; goto bail; } bundle.setProduct(argv[0]); } else if (strcmp(cp, "-non-constant-id") == 0) { bundle.setNonConstantId(true); } else if (strcmp(cp, "-no-crunch") == 0) { bundle.setUseCrunchCache(true); } else if (strcmp(cp, "-ignore-assets") == 0) { argc--; argv++; if (!argc) { fprintf(stderr, "ERROR: No argument supplied for '--ignore-assets' option\n"); wantUsage = true; goto bail; } gUserIgnoreAssets = argv[0]; } else { fprintf(stderr, "ERROR: Unknown option '-%s'\n", cp); wantUsage = true; goto bail; } cp += strlen(cp) - 1; break; default: fprintf(stderr, "ERROR: Unknown flag '-%c'\n", *cp); wantUsage = true; goto bail; } cp++; } argc--; argv++; } /* * We're past the flags. The rest all goes straight in. */ bundle.setFileSpec(argv, argc); result = handleCommand(&bundle); bail: if (wantUsage) { usage(); result = 2; } //printf("--> returning %d\n", result); return result; }
void QFirm::produceNext(const Bundle &b) { double quantity = b.coverage(output()); if (not std::isfinite(quantity)) throw supply_mismatch(); assets += quantity * output(); }