コード例 #1
0
ファイル: lpeg_tester.cpp プロジェクト: cluo/lpeg_tester
Wt::WWidget* Tester::Input()
{

    Wt::WContainerWidget* container = new Wt::WContainerWidget();
    container->setStyleClass("input_container");

    Wt::WText* t = new Wt::WText("Input", container);
    t->setStyleClass("area_title");
    new Wt::WBreak(container);
    mInput = new Wt::WTextArea(container);
    mInput->setText("20131220T094700");

    new Wt::WBreak(container);

    t = new Wt::WText("Grammar", container);
    t->setStyleClass("area_title");
    new Wt::WBreak(container);
    mGrammar = new Wt::WTextArea(container);
    mGrammar->setRows(15);
    mGrammar->setText("local l = require 'lpeg'\nl.locale(l)\ngrammar = l.C(l.digit^-4)");

    Wt::WPushButton* button = new Wt::WPushButton("Test Grammar", container);
    button->clicked().connect(this, &Tester::GrammarButton);

    button = new Wt::WPushButton("Benchmark Grammar", container);
    button->clicked().connect(this, &Tester::BenchmarkButton);

    button = new Wt::WPushButton("Share Grammar", container);
    button->clicked().connect(this, &Tester::ShareGrammar);

    return container;
}
コード例 #2
0
ファイル: lpeg_tester.cpp プロジェクト: cluo/lpeg_tester
void Tester::TestGrammar(bool benchmark)
{
    mResult->clear();

    fs::path grammar = fs::path("/tmp") / (sessionId() + ".lua");
    ofstream ofs(grammar.string().c_str());
    if (ofs) {
        ofs << mGrammar->text();
        ofs.close();
    } else {
        stringstream ss;
        ss << "failed to open: " << grammar;
        Wt::WText* t = new Wt::WText(ss.str(), mResult);
        t->setStyleClass("result_error");
        Wt::log("error") << ss.str();
        return;
    }
    lua_sandbox* sb = lsb_create(NULL, grammar.string().c_str(), "modules",
                                 8*1024*1024, 1e6, 1024*63);
    if (!sb) {
        stringstream ss;
        ss << "lsb_create() failed";
        Wt::WText* t = new Wt::WText(ss.str(), mResult);
        t->setStyleClass("result_error");
        Wt::log("error") << ss.str();
        return;
    }
    if (lsb_init(sb, nullptr)) {
        stringstream ss;
        string error = lsb_get_error(sb);
        size_t pos = error.find_first_of(':');
        if (pos != string::npos) {
            ss << "line " << error.substr(pos + 1);
        } else {
            ss << error;
        }
        Wt::WText* t = new Wt::WText(ss.str(), mResult);
        t->setStyleClass("result_error");
        Wt::log("info") << ss.str();
        return;

    }
    if (benchmark) {
        Benchmark(sb, mInput->text().narrow());
    } else {
        Match(sb, mInput->text().narrow());
    }
    char* e = lsb_destroy(sb, nullptr);
    if (e) {
        stringstream ss;
        ss << "lsb_destroy() failed: " << e;
        Wt::WText* t = new Wt::WText(ss.str(), mResult);
        t->setStyleClass("result_error");
        Wt::log("info") << ss.str();
        free(e);
    }
}
コード例 #3
0
ファイル: LocationTable.cpp プロジェクト: ulrichard/flugbuch
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8/////////9/////////A
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8/////////9/////////A
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8/////////9/////////A
LocationPanel::LocationPanel(boost::shared_ptr<FlightDatabase>  flightDb, Wt::WContainerWidget *parent)
 : Wt::WCompositeWidget(parent), flightDb_(flightDb), impl_(new Wt::WContainerWidget())
{
    setImplementation(impl_);
    setStyleClass("flb_detail_panel");
    impl_->setStyleClass("flb_detail_panel");

    cbArea_ = new Wt::Ext::ComboBox(impl_);
    cbTakeoff_ = new Wt::Ext::CheckBox(impl_);
	cbLanding_ = new Wt::Ext::CheckBox(impl_);
	cbWayPnt_  = new Wt::Ext::CheckBox(impl_);
    table_  = new LocationTable(flightDb, impl_);
    pglist_ = new PagesList(table_);
    // signals
    cbArea_->activated().connect(SLOT(this, LocationPanel::filter));
    cbTakeoff_->checked().connect(SLOT(this, LocationPanel::filter));
    cbLanding_->checked().connect(SLOT(this, LocationPanel::filter));
    cbWayPnt_->checked().connect(SLOT(this, LocationPanel::filter));
    cbTakeoff_->unChecked().connect(SLOT(this, LocationPanel::filter));
    cbLanding_->unChecked().connect(SLOT(this, LocationPanel::filter));
    cbWayPnt_->unChecked().connect(SLOT(this, LocationPanel::filter));

    // header
    Wt::WTable *topBar = new Wt::WTable();
    topBar->setStyleClass("FilterBar");
    Wt::WText *wtFilt = new Wt::WText("Filter : ");
    wtFilt->setStyleClass("FilterTitle");
    Wt::WText *wtArea = new Wt::WText("Fluggebiet");
    wtArea->setStyleClass("FilterSubTitle");
    cbTakeoff_->setText("Startplaetze");
    cbLanding_->setText("Landeplaetze");
    cbWayPnt_->setText("Wegpunkte");
    topBar->elementAt(0, 0)->addWidget(wtFilt);
    topBar->elementAt(0, 1)->addWidget(wtArea);
    topBar->elementAt(0, 2)->addWidget(cbArea_);
    topBar->elementAt(0, 3)->addWidget(cbTakeoff_);
    topBar->elementAt(0, 4)->addWidget(cbLanding_);
    topBar->elementAt(0, 5)->addWidget(cbWayPnt_);
    topBar->elementAt(0, 6)->addWidget(pglist_);

    Wt::WContainerWidget *botBar = new Wt::WContainerWidget();

    Wt::WBorderLayout *borderLayout = new Wt::WBorderLayout();
    impl_->setLayout(borderLayout);
    borderLayout->addWidget(topBar, Wt::WBorderLayout::North);
    borderLayout->addWidget(table_, Wt::WBorderLayout::Center);
    borderLayout->addWidget(botBar, Wt::WBorderLayout::South);

    load();
    filter();
}
コード例 #4
0
ファイル: lpeg_tester.cpp プロジェクト: cluo/lpeg_tester
void Tester::LoadGrammar()
{
    string h = internalPathNextPart("/share/");
    fs::path input = fs::path(appRoot()) / "share" / (h + ".data");
    mInput->setText("");
    mGrammar->setText("");
    mResult->clear();

    ifstream data_fs(input.string().c_str());
    if (data_fs) {
        data_fs.unsetf(std::ios::skipws);
        string data((istream_iterator<char>(data_fs)), istream_iterator<char>());
        mInput->setText(data);
        data_fs.close();
    } else {
        stringstream ss;
        ss << "share not found: " << h;
        Wt::WText* t = new Wt::WText(ss.str(), mResult);
        t->setStyleClass("result_error");
        Wt::log("info") << ss.str();
        return;
    }

    fs::path grammar = fs::path(appRoot()) / "share" / (h + ".lua");
    ifstream grammar_fs(grammar.string().c_str());
    if (grammar_fs) {
        grammar_fs.unsetf(std::ios::skipws);
        string data((istream_iterator<char>(grammar_fs)), istream_iterator<char>());
        mGrammar->setText(data);
        grammar_fs.close();
    }
}
コード例 #5
0
ファイル: lpeg_tester.cpp プロジェクト: cluo/lpeg_tester
void Tester::ShareGrammar()
{
    boost::hash<std::string> string_hash;
    string data(mInput->text().narrow() + mGrammar->text().narrow());
    string h = boost::lexical_cast<string>(string_hash(data));
    fs::path input = fs::path(appRoot()) / "share" / (h + ".data");
    if (!exists(input)) {
        ofstream data_fs(input.string().c_str());
        if (data_fs) {
            data_fs << mInput->text();
            data_fs.close();
        } else {
            stringstream ss;
            ss << "failed to open: " << input;
            Wt::WText* t = new Wt::WText(ss.str(), mResult);
            t->setStyleClass("result_error");
            Wt::log("error") << ss.str();
            return;
        }

        fs::path grammar = fs::path(appRoot()) / "share" / (h + ".lua");
        ofstream lua_fs(grammar.string().c_str());
        if (lua_fs) {
            lua_fs << mGrammar->text();
            lua_fs.close();
        } else {
            stringstream ss;
            ss << "failed to open: " << grammar;
            Wt::WText* t = new Wt::WText(ss.str(), mResult);
            t->setStyleClass("result_error");
            Wt::log("error") << ss.str();
            return;
        }
    }

    setInternalPath("/share/" + h);
    Wt::WMessageBox* messageBox = new Wt::WMessageBox("Share", makeAbsoluteUrl(bookmarkUrl()), Wt::Information, Wt::Ok);
    messageBox->buttonClicked().connect(std::bind([=]() {
        delete messageBox;
    }));
    messageBox->show();
}
コード例 #6
0
      WebApp::WebApp(const Wt::WEnvironment & env) : WApplication(env) {
        if (string(org::esb::config::Config::getProperty("hive.mode")) == "setup") {
          WApplication::instance()->redirect("/setup");
          WApplication::instance()->quit();
        }
        setTitle("Hive Webadmin");
        _isAuthenticated = false;
        Wt::Ext::Container *viewPort = new Wt::Ext::Container(root());
        Wt::WBorderLayout *layout = new Wt::WBorderLayout(viewPort);


        Wt::Ext::Panel *north = new Wt::Ext::Panel();
        north->setBorder(false);
        std::string h = "MediaEncodingCluster V-";
        h += MHIVE_VERSION;
        h += "($Rev$-"__DATE__ "-" __TIME__")";
        Wt::WText *head = new Wt::WText(h);
        head->setStyleClass("north");
        north->setLayout(new Wt::WFitLayout());
        north->layout()->addWidget(head);
        north->resize(Wt::WLength(), 35);
        layout->addWidget(north, Wt::WBorderLayout::North);

        /* West */
        west = new Wt::Ext::Panel();

        west->setTitle("Menu");
        west->resize(200, Wt::WLength());
        west->setResizable(true);
        west->collapse();
        west->setAnimate(true);
        west->setAutoScrollBars(true);
        layout->addWidget(west, Wt::WBorderLayout::West);


        /* Center */
        Wt::Ext::Panel *center = new Wt::Ext::Panel();
        center->setTitle("MediaEncodingCluster");
        center->layout()->addWidget(exampleContainer_ = new Wt::WContainerWidget());
        center->setAutoScrollBars(true);
        layout->addWidget(center, Wt::WBorderLayout::Center);

        exampleContainer_->setPadding(5);

        currentExample_ = login = new Login(exampleContainer_);
        login->authenticated.connect(SLOT(this, WebApp::authenticated));
        //        useStyleSheet("ext/resources/css/xtheme-gray.css");
        useStyleSheet("filetree.css");
        useStyleSheet("main.css");
        std::string res = std::string(Config::getProperty("hive.path"));
        res.append("/../res/messages");
        messageResourceBundle().use(res.c_str(), false);

      }
コード例 #7
0
ファイル: LocationTable.cpp プロジェクト: ulrichard/flugbuch
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8/////////9/////////A
void LocationTable::createHeaderRow()
{
    static const std::string captions[7] = {"Gebiet", "Name", "Höhe", "Position", "SP", "LP", "WP"};
    for(size_t i=0; i<sizeof(captions) / sizeof(std::string); ++i)
    {
        Wt::WText *labelText = new Wt::WText(captions[i]);
        labelText->setStyleClass("tableHeader");
        elementAt(0, i + 1)->addWidget(labelText);
    }
    rowAt(0)->setStyleClass("title");
}
コード例 #8
0
ファイル: lpeg_tester.cpp プロジェクト: cluo/lpeg_tester
Wt::WWidget* Tester::Result()
{
    Wt::WContainerWidget* c = new Wt::WContainerWidget();
    c->setStyleClass("result_container");

    Wt::WText* t = new Wt::WText("Results", c);
    t->setStyleClass("area_title");

    mResult = new Wt::WContainerWidget(c);
    mResult->setStyleClass("result_output");

    return c;
}
コード例 #9
0
ファイル: PopupChatWidget.C プロジェクト: ReWeb3D/wt
Wt::WContainerWidget *PopupChatWidget::createBar() 
{
  Wt::WContainerWidget *bar = new Wt::WContainerWidget();
  bar->setStyleClass("chat-bar");

  Wt::WText *toggleButton = new Wt::WText();
  toggleButton->setInline(false);
  toggleButton->setStyleClass("chat-minmax");
  bar->clicked().connect(this, &PopupChatWidget::toggleSize);
  bar->clicked().connect(this, &PopupChatWidget::goOnline);

  bar->addWidget(toggleButton);

  title_ = new Wt::WText(bar);

  bar_ = bar;

  return bar;
}
コード例 #10
0
ファイル: LocationTable.cpp プロジェクト: ulrichard/flugbuch
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8/////////9/////////A
void LocationTableRow::show()
{
	clearRow();

    // the edit image
	Wt::WImage *wiEdit = new Wt::WImage("img/edit.png");
	wiEdit->setToolTip("Ort bearbeiten");
	wiEdit->setStyleClass("operationImg");
	table_->elementAt(rowNr_, colOp)->addWidget(wiEdit);
	wiEdit->clicked().connect(SLOT(this, LocationTableRow::edit));
    // the delete image
	Wt::WImage *wiDelete = new Wt::WImage("img/delete.png");
	wiDelete->setToolTip("Ort löschen");
	wiDelete->setStyleClass("operationImg");
	table_->elementAt(rowNr_, colOp)->addWidget(wiDelete);
	wiDelete->clicked().connect(SLOT(this, LocationTableRow::remove));
	// the map image
//	WImage *wiMap = new WImage("img/map.png");
//	wiMap->setToolTip("position anschauen");
//    wiMap->setStyleClass("operationImg");
//	table_->elementAt(rowNr_, colOp)->addWidget(wiMap);
//	wiMap->clicked.connect(SLOT(this, LocationTableRow::map));

	// prepare the text
	std::vector<std::string> vsText;
	vsText.push_back(location_->area()->name());
	vsText.push_back(location_->name());
	vsText.push_back(boost::lexical_cast<std::string>(location_->height()));
	vsText.push_back(Wt::WGeoPosEdit::format(std::make_pair(location_->pos().first, location_->pos().second), Wt::WGeoPosEdit::WGS84_SEC));
	vsText.push_back(location_->usage() & Location::UA_TAKEOFF ? "x" : "_");
	vsText.push_back(location_->usage() & Location::UA_LANDING ? "x" : "_");
	vsText.push_back(location_->usage() & Location::UA_WAYPNT  ? "x" : "_");
	// add the text widgets
	for(size_t i=0; i<vsText.size(); ++i)
	{
		Wt::WText *wtxt = new Wt::WText(vsText[i]);
		wtxt->setStyleClass("tableContent");
		table_->elementAt(rowNr_, i + 1)->addWidget(wtxt);
	}
}
コード例 #11
0
ファイル: EditUsers.cpp プロジェクト: lyase/install
/* ****************************************************************************
 * Limit List
 */
void EditUsers::LimitList()
{
    Wt::WContainerWidget* list = new Wt::WContainerWidget;
    bindWidget("user-list",list);

    typedef Wt::Dbo::collection<Wt::Dbo::ptr<User> > UserList;
    Wt::Dbo::Transaction t(session_);
    UserList users = session_.find<User>().where("name like ?").bind("%"+limitEdit_->text()+"%").orderBy("name");

    Wt::WSignalMapper<Wt::Dbo::dbo_traits<User>::IdType >* userLinkMap = new Wt::WSignalMapper<Wt::Dbo::dbo_traits<User>::IdType >(this);
    userLinkMap->mapped().connect(this,&EditUsers::OnUserClicked);
    for (UserList::const_iterator i = users.begin(); i != users.end(); ++i)
    {
        Wt::WText* t = new Wt::WText((*i)->name, list);
        t->setStyleClass("link");
        new Wt::WBreak(list);
        userLinkMap->mapConnect(t->clicked(), (*i).id());
    }
    if (!users.size())
    {
        new Wt::WText(tr("no-users-found"),list);
    }
} // end void EditUsers::LimitList
コード例 #12
0
ファイル: lpeg_tester.cpp プロジェクト: cluo/lpeg_tester
void Tester::Benchmark(lua_sandbox* lsb, const string& input)
{
    lua_State* lua = lsb_get_lua(lsb);
    if (!lua) return;
    bool nomatch = false;

    if (!CreateGlobalMatch(lua)) {
        stringstream ss;
        ss << "lpeg.match is not available";
        Wt::WText* t = new Wt::WText(ss.str(), mResult);
        t->setStyleClass("result_error");
        Wt::log("info") << ss.str();
        return;
    }

    clock_t t = clock();
    int x, iter = 10000;
    for (x = 0; x < iter; ++x) {
        if (lsb_pcall_setup(lsb, kMatchFunction)) {
            stringstream ss;
            ss << "lsb_pcall_setup() failed";
            Wt::WText* t = new Wt::WText(ss.str(), mResult);
            t->setStyleClass("result_error");
            Wt::log("info") << ss.str();
            return;
        }

        lua_getglobal(lua, "grammar");
        if (!lua_isuserdata(lua, -1)) {
            stringstream ss;
            ss << "no global grammar variable was found";
            Wt::WText* t = new Wt::WText(ss.str(), mResult);
            t->setStyleClass("result_error");
            Wt::log("info") << ss.str();
            return;
        }

        lua_pushstring(lua, input.c_str());
        if (lua_pcall(lua, 2, LUA_MULTRET, 0) != 0) {
            char err[LSB_ERROR_SIZE];
            int len = snprintf(err, LSB_ERROR_SIZE, "%s() %s", kMatchFunction,
                               lua_tostring(lua, -1));
            if (len >= LSB_ERROR_SIZE || len < 0) {
                err[LSB_ERROR_SIZE - 1] = 0;
            }
            stringstream ss;
            ss << err;
            Wt::WText* t = new Wt::WText(ss.str(), mResult);
            t->setStyleClass("result_error");
            Wt::log("info") << ss.str();
            lsb_terminate(lsb, err);
            return;
        } else {
            if (LUA_TNIL == lua_type(lua, 1)) {
                nomatch = true;
            }
        }
        lua_pop(lua, lua_gettop(lua)); // clear the stack
    }
    t = clock() - t;
    stringstream ss;
    Wt::WText* txt = new Wt::WText(mResult);
    if (nomatch) {
        txt->setStyleClass("result_error");
        ss << " *** MATCH FAILED ***<br/>";
    }
    ss << "Benchmark"
       << "<br/>samples: " << x
       << "<br/>seconds per match: " << (((float)t) / CLOCKS_PER_SEC / x)
       << "<br/>max memory (bytes): " << lsb_usage(lsb, LSB_UT_MEMORY, LSB_US_MAXIMUM)
       << "<br/>max Lua instructions: " << lsb_usage(lsb, LSB_UT_INSTRUCTION, LSB_US_MAXIMUM);
    txt->setText(ss.str());
    lsb_pcall_teardown(lsb);
}
コード例 #13
0
ファイル: lpeg_tester.cpp プロジェクト: cluo/lpeg_tester
void Tester::Match(lua_sandbox* lsb, const string& input)
{
    lua_State* lua = lsb_get_lua(lsb);
    if (!lua) return;

    if (!CreateGlobalMatch(lua)) {
        stringstream ss;
        ss << "lpeg.match is not available";
        Wt::WText* t = new Wt::WText(ss.str(), mResult);
        t->setStyleClass("result_error");
        Wt::log("info") << ss.str();
        return;
    }

    if (lsb_pcall_setup(lsb, kMatchFunction)) {
        stringstream ss;
        ss << "lsb_pcall_setup() failed";
        Wt::WText* t = new Wt::WText(ss.str(), mResult);
        t->setStyleClass("result_error");
        Wt::log("info") << ss.str();
        return;
    }

    lua_getglobal(lua, "grammar");
    if (!lua_isuserdata(lua, -1)) {
        stringstream ss;
        ss << "no global grammar variable was found";
        Wt::WText* t = new Wt::WText(ss.str(), mResult);
        t->setStyleClass("result_error");
        Wt::log("info") << ss.str();
        return;
    }

    lua_pushstring(lua, input.c_str());
    if (lua_pcall(lua, 2, LUA_MULTRET, 0) != 0) {
        char err[LSB_ERROR_SIZE];
        int len = snprintf(err, LSB_ERROR_SIZE, "%s() %s", kMatchFunction,
                           lua_tostring(lua, -1));
        if (len >= LSB_ERROR_SIZE || len < 0) {
            err[LSB_ERROR_SIZE - 1] = 0;
        }
        stringstream ss;
        ss << err;
        Wt::WText* t = new Wt::WText(ss.str(), mResult);
        t->setStyleClass("result_error");
        Wt::log("info") << ss.str();
        lsb_terminate(lsb, err);
        return;
    }
    // iterater over the results
    int results = lua_gettop(lua);
    if (LUA_TNIL == lua_type(lua, 1)) {
        stringstream ss;
        ss << "no match";
        Wt::WText* t = new Wt::WText(ss.str(), mResult);
        t->setStyleClass("result_error");
    } else {
        Wt::WTree* tree = new Wt::WTree(mResult);
        tree->setSelectionMode(Wt::SingleSelection);
        Wt::WTreeNode* root = new Wt::WTreeNode("Returned Values");
        root->setStyleClass("tree_results");
        tree->setTreeRoot(root);
        root->label()->setTextFormat(Wt::PlainText);
        root->setLoadPolicy(Wt::WTreeNode::NextLevelLoading);
        for (int i = 1; i <= results; ++i) {
            stringstream ss;
            OutputItem(lua, i, root, ss);
        }
        root->expand();
    }
    lua_pop(lua, lua_gettop(lua)); // clear the stack
    lsb_pcall_teardown(lsb);
}