int main(int argc, char* argv[]) { double strike = 50.0; double expiry = 90; std::unique_ptr<PayOff> payOffUnique( new PayOffCall(strike) ); std::shared_ptr<PayOff> payOffShared( new PayOffCall(strike) ); double spot = 60; OptionUnique option1( std::move(payOffUnique), expiry ); std::cout << option1(spot) << std::endl; // Can't reuse unique_ptr - seg faults at run time if we try // since payOffUnique now just contains NULL // OptionUnique option2( std::move(payOffUnique), expiry ); auto option2 = std::move(option1); // Can move option std::cout << option2(spot) << std::endl; // Now option1 is invalid and seg faults if used. // std::cout << option1(spot) << std::endl; // Can reuse shared_ptr OptionShared option3( payOffShared, expiry ); std::cout << option3(spot) << std::endl; OptionShared option4( payOffShared, expiry ); std::cout << option4(spot) << std::endl; auto option5 = option4; std::cout << option5(spot) << std::endl; return 0; }
void net_io::set_options() { if (_socket.is_open()) { try { boost::asio::socket_base::send_buffer_size option, option2(16 * 1024 * 1024); _socket.get_option(option); int old = option.value(); _socket.set_option(option2); _socket.get_option(option); /*ddebug("boost asio send buffer size is %u, set as 16MB, now is %u", old, option.value());*/ boost::asio::socket_base::receive_buffer_size option3, option4(16 * 1024 * 1024); _socket.get_option(option3); old = option3.value(); _socket.set_option(option4); _socket.get_option(option3); /*ddebug("boost asio recv buffer size is %u, set as 16MB, now is %u", old, option.value());*/ } catch (std::exception& ex) { dwarn("network session %s:%d set socket option failed, err = %s", _remote_addr.to_ip_string().c_str(), static_cast<int>(_remote_addr.port), ex.what() ); } } }
void asio_rpc_session::set_options() { if (_socket->is_open()) { try { boost::asio::socket_base::send_buffer_size option, option2(16 * 1024 * 1024); _socket->get_option(option); int old = option.value(); _socket->set_option(option2); _socket->get_option(option); dinfo("boost asio send buffer size is %u, set as 16MB, now is %u", old, option.value()); boost::asio::socket_base::receive_buffer_size option3, option4(16 * 1024 * 1024); _socket->get_option(option3); old = option3.value(); _socket->set_option(option4); _socket->get_option(option3); dinfo("boost asio recv buffer size is %u, set as 16MB, now is %u", old, option.value()); } catch (std::exception& ex) { dwarn("network session 0x%x:%hu set socket option failed, err = %s", remote_address().ip(), remote_address().port(), ex.what() ); } } }
END_TEST START_TEST (test_conversion_options_constructor) { ConversionOption option1("key", "test", ""); fail_unless(option1.getValue() == "test"); fail_unless(option1.getType() == CNV_TYPE_STRING); ConversionOption option2("key", 1.1, ""); fail_unless(option2.getDoubleValue() == 1.1); fail_unless(option2.getType() == CNV_TYPE_DOUBLE); ConversionOption option3("key", 1.1f, ""); fail_unless(option3.getFloatValue() == 1.1f); fail_unless(option3.getType() == CNV_TYPE_SINGLE); ConversionOption option4("key", 10, ""); fail_unless(option4.getIntValue() == 10); fail_unless(option4.getType() == CNV_TYPE_INT); ConversionOption option5("key", false, ""); fail_unless(option5.getBoolValue() == false); fail_unless(option5.getType() == CNV_TYPE_BOOL); }
void ElementItemDelegate::paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const { baseDelegate->paint(painter, option, index); Element * element = Element::fromModelIndex(index); if(NULL != element) { QStyleOptionViewItemV4 option4(option); QRect markRect = option.rect; int startPosition = static_cast<const QTreeWidget*>(option4.widget)->columnViewportPosition(0) ; markRect.setLeft(startPosition); markRect.setWidth(WIDTH_BAND); if(element->saved()) { painter->fillRect(markRect, savedBrush); } else if(element->edited()) { painter->fillRect(markRect, editedBrush); } else { painter->fillRect(markRect, normalBrush); } } }
int main(int argc, char **argv) { if (argc < 3) { printf("Usage: ./104systemes and requiered arguments.\n"); exit(EXIT_FAILURE); } else { if (argv[1][0] == '1') option1(argv); if (argv[1][0] == '2') option2(argv); if (argv[1][0] == '3') option3(argv); if (argv[1][0] == '4') option4(argv); } return (0); }
int main() { int i = get_option(); while (i < 1 || i > 5) { printf("You have entered an invalid input character. Please try again.\n\n"); i = get_option(); } if (i == 1) option1(); else if (i == 2) option2(); else if (i == 3) option3(); else if (i == 4) option4(); else if (i == 5) exit(1); //system("pause"); return 0; }
bool gol::RendererSFML::menu() { m_seedChoice = 0; float fontSize = 20.f; sf::Vector2f textPosition = sf::Vector2f(20.f, 20.f); sf::Text title("CONWAY'S GAME OF LIFE", m_golbalFont, fontSize + 30.f); title.setColor(sf::Color::Green); title.setPosition(sf::Vector2f(textPosition.x, textPosition.y)); sf::Text options("SELECT YOUR CHOICE :-", m_golbalFont, fontSize + 10.f); options.setColor(sf::Color::Red); options.setPosition(sf::Vector2f(textPosition.x, textPosition.y + 70.f)); sf::Text option1("1. Blinker Seed", m_golbalFont, fontSize); option1.setColor(sf::Color::White); option1.setPosition(sf::Vector2f(textPosition.x, textPosition.y + 120.f)); sf::Text option2("2. Toad Seed", m_golbalFont, fontSize); option2.setColor(sf::Color::White); option2.setPosition(sf::Vector2f(textPosition.x, textPosition.y + 145.f)); sf::Text option3("3. Beacon Seed", m_golbalFont, fontSize); option3.setColor(sf::Color::White); option3.setPosition(sf::Vector2f(textPosition.x, textPosition.y + 170.f)); sf::Text option4("4. Pulsar Seed", m_golbalFont, fontSize); option4.setColor(sf::Color::White); option4.setPosition(sf::Vector2f(textPosition.x, textPosition.y + 195.f)); sf::Text option5("5. Glider Seed", m_golbalFont, fontSize); option5.setColor(sf::Color::White); option5.setPosition(sf::Vector2f(textPosition.x, textPosition.y + 220.f)); sf::Text option6("6. Lightweight spaceship (LWSS) Seed", m_golbalFont, fontSize); option6.setColor(sf::Color::White); option6.setPosition(sf::Vector2f(textPosition.x, textPosition.y + 245.f)); sf::Text option7("7. Gosper Glider Gun Seed", m_golbalFont, fontSize); option7.setColor(sf::Color::White); option7.setPosition(sf::Vector2f(textPosition.x, textPosition.y + 270.f)); sf::Text option8("8. R-pentomino Seed", m_golbalFont, fontSize); option8.setColor(sf::Color::White); option8.setPosition(sf::Vector2f(textPosition.x, textPosition.y + 295.f)); sf::Text option9("9. Diehard Seed", m_golbalFont, fontSize); option9.setColor(sf::Color::White); option9.setPosition(sf::Vector2f(textPosition.x, textPosition.y + 325.f)); sf::Text option10("10. Acorn Seed", m_golbalFont, fontSize); option10.setColor(sf::Color::White); option10.setPosition(sf::Vector2f(textPosition.x, textPosition.y + 350.f)); sf::Text option11("11. SPECIFY YOUR OWN SEED", m_golbalFont, fontSize); option11.setColor(sf::Color::White); option11.setPosition(sf::Vector2f(textPosition.x, textPosition.y + 375.f)); sf::Text option12("12. EXIT", m_golbalFont, fontSize); option12.setColor(sf::Color::White); option12.setPosition(sf::Vector2f(textPosition.x, textPosition.y + 400.f)); sf::Text choiceLabel("YOUR CHOICE : ", m_golbalFont, fontSize); choiceLabel.setColor(sf::Color::White); choiceLabel.setPosition(sf::Vector2f(textPosition.x, textPosition.y + 455.f)); sf::Text choiceText("", m_golbalFont, fontSize); choiceText.setColor(sf::Color::Cyan); choiceText.setPosition(sf::Vector2f(textPosition.x + 170.f, textPosition.y + 455.f)); sf::String choiceString; sf::Text userSeedLabel("ENTER THE SEED FILE NAME : ", m_golbalFont, fontSize); userSeedLabel.setColor(sf::Color::Green); userSeedLabel.setPosition(sf::Vector2f(textPosition.x, textPosition.y + 500.f)); sf::Text userSeedText("", m_golbalFont, fontSize); userSeedText.setColor(sf::Color::Cyan); userSeedText.setPosition(sf::Vector2f(textPosition.x + 320.f, textPosition.y + 500.f)); sf::String userSeedString; std::string customSeedFile; bool isInMainMenu = true; while(m_window.isOpen()) { sf::Event event; while(m_window.pollEvent(event)) { if(event.type == sf::Event::Closed) { m_window.close(); return false; } if(event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Return) { if(m_seedChoice != 0) { if(m_seedChoice == 12) return false; else if(m_seedChoice == 11) isInMainMenu = false; else if(m_seedChoice < 11) return true; } } if(event.type == sf::Event::TextEntered && isInMainMenu) { if(event.text.unicode >= 48 && event.text.unicode <= 57) choiceString += (char)event.text.unicode; else if(event.text.unicode == 8 && choiceString.getSize() > 0) choiceString.erase(choiceString.getSize() - 1, choiceString.getSize()); choiceText.setString(choiceString); std::string str = choiceString.toAnsiString(); m_seedChoice = std::atoi(str.c_str()); } if(m_seedChoice == 11 && !isInMainMenu) { if(event.type == sf::Event::TextEntered) { if((event.text.unicode >= 32 && event.text.unicode <= 57) || (event.text.unicode >= 64 && event.text.unicode <= 126)) userSeedString += (char)event.text.unicode; else if(event.text.unicode == 8 && userSeedString.getSize() > 0) userSeedString.erase(userSeedString.getSize() - 1, userSeedString.getSize()); userSeedText.setString(userSeedString); } if(event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Return && !userSeedString.isEmpty()) { customSeedFile = userSeedString.toAnsiString(); setSeedFileName(customSeedFile); return true; } } } m_window.clear(sf::Color::Black); m_window.draw(title); m_window.draw(options); m_window.draw(option1); m_window.draw(option2); m_window.draw(option3); m_window.draw(option4); m_window.draw(option5); m_window.draw(option6); m_window.draw(option7); m_window.draw(option8); m_window.draw(option9); m_window.draw(option10); m_window.draw(option11); m_window.draw(option12); m_window.draw(choiceLabel); m_window.draw(choiceText); if(!isInMainMenu) { m_window.draw(userSeedLabel); m_window.draw(userSeedText); } m_window.display(); } }