Beispiel #1
0
QT_BEGIN_NAMESPACE

QXcbScreen::QXcbScreen(QXcbConnection *connection, xcb_screen_t *scr,
                       xcb_randr_get_output_info_reply_t *output, QString outputName, int number)
    : QXcbObject(connection)
    , m_screen(scr)
    , m_crtc(output ? output->crtc : 0)
    , m_outputName(outputName)
    , m_sizeMillimeters(output ? QSize(output->mm_width, output->mm_height) : QSize())
    , m_virtualSize(scr->width_in_pixels, scr->height_in_pixels)
    , m_virtualSizeMillimeters(scr->width_in_millimeters, scr->height_in_millimeters)
    , m_orientation(Qt::PrimaryOrientation)
    , m_number(number)
    , m_refreshRate(60)
    , m_forcedDpi(-1)
    , m_hintStyle(QFontEngine::HintStyle(-1))
    , m_xSettings(0)
{
    if (connection->hasXRandr())
        xcb_randr_select_input(xcb_connection(), screen()->root, true);

    updateGeometry(output ? output->timestamp : 0);
    updateRefreshRate();

    // On VNC, it can be that physical size is unknown while
    // virtual size is known (probably back-calculated from DPI and resolution)
    if (m_sizeMillimeters.isEmpty())
        m_sizeMillimeters = m_virtualSizeMillimeters;
    if (m_geometry.isEmpty())
        m_geometry = QRect(QPoint(), m_virtualSize);
    if (m_availableGeometry.isEmpty())
        m_availableGeometry = QRect(QPoint(), m_virtualSize);

    readXResources();


#ifdef Q_XCB_DEBUG
    qDebug();
    qDebug("Screen output %s of xcb screen %d:", m_outputName.toUtf8().constData(), m_number);
    qDebug("  width..........: %lf", m_sizeMillimeters.width());
    qDebug("  height.........: %lf", m_sizeMillimeters.height());
    qDebug("  geometry.......: %d x %d +%d +%d", m_geometry.width(), m_geometry.height(), m_geometry.x(), m_geometry.y());
    qDebug("  virtual width..: %lf", m_virtualSizeMillimeters.width());
    qDebug("  virtual height.: %lf", m_virtualSizeMillimeters.height());
    qDebug("  virtual geom...: %d x %d", m_virtualSize.width(), m_virtualSize.height());
    qDebug("  avail virt geom: %d x %d +%d +%d", m_availableGeometry.width(), m_availableGeometry.height(), m_availableGeometry.x(), m_availableGeometry.y());
    qDebug("  depth..........: %d", screen()->root_depth);
    qDebug("  white pixel....: %x", screen()->white_pixel);
    qDebug("  black pixel....: %x", screen()->black_pixel);
    qDebug("  refresh rate...: %d", m_refreshRate);
    qDebug("  root ID........: %x", screen()->root);
#endif

    const quint32 mask = XCB_CW_EVENT_MASK;
    const quint32 values[] = {
        // XCB_CW_EVENT_MASK
        XCB_EVENT_MASK_ENTER_WINDOW
        | XCB_EVENT_MASK_LEAVE_WINDOW
        | XCB_EVENT_MASK_PROPERTY_CHANGE
        | XCB_EVENT_MASK_STRUCTURE_NOTIFY // for the "MANAGER" atom (system tray notification).
    };

    xcb_change_window_attributes(xcb_connection(), screen()->root, mask, values);

    xcb_get_property_reply_t *reply =
        xcb_get_property_reply(xcb_connection(),
            xcb_get_property_unchecked(xcb_connection(), false, screen()->root,
                             atom(QXcbAtom::_NET_SUPPORTING_WM_CHECK),
                             XCB_ATOM_WINDOW, 0, 1024), NULL);

    if (reply && reply->format == 32 && reply->type == XCB_ATOM_WINDOW) {
        xcb_window_t windowManager = *((xcb_window_t *)xcb_get_property_value(reply));

        if (windowManager != XCB_WINDOW_NONE) {
            xcb_get_property_reply_t *windowManagerReply =
                xcb_get_property_reply(xcb_connection(),
                    xcb_get_property_unchecked(xcb_connection(), false, windowManager,
                                     atom(QXcbAtom::_NET_WM_NAME),
                                     atom(QXcbAtom::UTF8_STRING), 0, 1024), NULL);
            if (windowManagerReply && windowManagerReply->format == 8 && windowManagerReply->type == atom(QXcbAtom::UTF8_STRING)) {
                m_windowManagerName = QString::fromUtf8((const char *)xcb_get_property_value(windowManagerReply), xcb_get_property_value_length(windowManagerReply));
#ifdef Q_XCB_DEBUG
                qDebug("  window manager.: %s", qPrintable(m_windowManagerName));
                qDebug();
#endif
            }

            free(windowManagerReply);
        }
    }
    free(reply);

    const xcb_query_extension_reply_t *sync_reply = xcb_get_extension_data(xcb_connection(), &xcb_sync_id);
    if (!sync_reply || !sync_reply->present)
        m_syncRequestSupported = false;
    else
        m_syncRequestSupported = true;

    m_clientLeader = xcb_generate_id(xcb_connection());
    Q_XCB_CALL2(xcb_create_window(xcb_connection(),
                                  XCB_COPY_FROM_PARENT,
                                  m_clientLeader,
                                  screen()->root,
                                  0, 0, 1, 1,
                                  0,
                                  XCB_WINDOW_CLASS_INPUT_OUTPUT,
                                  screen()->root_visual,
                                  0, 0), connection);
#ifndef QT_NO_DEBUG
    QByteArray ba("Qt client leader window for screen ");
    ba += m_outputName.toUtf8();
    Q_XCB_CALL2(xcb_change_property(xcb_connection(),
                                   XCB_PROP_MODE_REPLACE,
                                   m_clientLeader,
                                   atom(QXcbAtom::_NET_WM_NAME),
                                   atom(QXcbAtom::UTF8_STRING),
                                   8,
                                   ba.length(),
                                   ba.constData()), connection);
#endif

    Q_XCB_CALL2(xcb_change_property(xcb_connection(),
                                    XCB_PROP_MODE_REPLACE,
                                    m_clientLeader,
                                    atom(QXcbAtom::WM_CLIENT_LEADER),
                                    XCB_ATOM_WINDOW,
                                    32,
                                    1,
                                    &m_clientLeader), connection);

    xcb_depth_iterator_t depth_iterator =
        xcb_screen_allowed_depths_iterator(screen());

    while (depth_iterator.rem) {
        xcb_depth_t *depth = depth_iterator.data;
        xcb_visualtype_iterator_t visualtype_iterator =
            xcb_depth_visuals_iterator(depth);

        while (visualtype_iterator.rem) {
            xcb_visualtype_t *visualtype = visualtype_iterator.data;
            m_visuals.insert(visualtype->visual_id, *visualtype);
            xcb_visualtype_next(&visualtype_iterator);
        }

        xcb_depth_next(&depth_iterator);
    }

    m_cursor = new QXcbCursor(connection, this);
}
bool parse_and_validate_block_from_blob(const blobdata& b_blob, Block& b) {
  std::stringstream ss;
  ss << b_blob;
  binary_archive<false> ba(ss);
  return ::serialization::serialize(ba, b);
}
Beispiel #3
0
void wrapInFunction()
{

//! [0]
QByteArray ba("Hello");
//! [0]


//! [1]
QByteArray ba;
ba.resize(5);
ba[0] = 0x3c;
ba[1] = 0xb8;
ba[2] = 0x64;
ba[3] = 0x18;
ba[4] = 0xca;
//! [1]


//! [2]
for (int i = 0; i < ba.size(); ++i) {
    if (ba.at(i) >= 'a' && ba.at(i) <= 'f')
        cout << "Found character in range [a-f]" << endl;
}
//! [2]


//! [3]
QByteArray x("and");
x.prepend("rock ");         // x == "rock and"
x.append(" roll");          // x == "rock and roll"
x.replace(5, 3, "&");       // x == "rock & roll"
//! [3]


//! [4]
QByteArray ba("We must be <b>bold</b>, very <b>bold</b>");
int j = 0;
while ((j = ba.indexOf("<b>", j)) != -1) {
    cout << "Found <b> tag at index position " << j << endl;
    ++j;
}
//! [4]


//! [5]
QByteArray().isNull();          // returns true
QByteArray().isEmpty();         // returns true

QByteArray("").isNull();        // returns false
QByteArray("").isEmpty();       // returns true

QByteArray("abc").isNull();     // returns false
QByteArray("abc").isEmpty();    // returns false
//! [5]


//! [6]
QByteArray ba("Hello");
int n = ba.size();          // n == 5
ba.data()[0];               // returns 'H'
ba.data()[4];               // returns 'o'
ba.data()[5];               // returns '\0'
//! [6]


//! [7]
QByteArray().isEmpty();         // returns true
QByteArray("").isEmpty();       // returns true
QByteArray("abc").isEmpty();    // returns false
//! [7]


//! [8]
QByteArray ba("Hello world");
char *data = ba.data();
while (*data) {
    cout << "[" << *data << "]" << endl;
    ++data;
}
//! [8]


//! [9]
QByteArray ba;
for (int i = 0; i < 10; ++i)
    ba[i] = 'A' + i;
// ba == "ABCDEFGHIJ"
//! [9]


//! [10]
QByteArray ba("Stockholm");
ba.truncate(5);             // ba == "Stock"
//! [10]


//! [11]
QByteArray ba("STARTTLS\r\n");
ba.chop(2);                 // ba == "STARTTLS"
//! [11]


//! [12]
QByteArray x("free");
QByteArray y("dom");
x += y;
// x == "freedom"
//! [12]


//! [13]
QByteArray().isNull();          // returns true
QByteArray("").isNull();        // returns false
QByteArray("abc").isNull();     // returns false
//! [13]


//! [14]
QByteArray ba("Istambul");
ba.fill('o');
// ba == "oooooooo"

ba.fill('X', 2);
// ba == "XX"
//! [14]


//! [15]
QByteArray x("ship");
QByteArray y("air");
x.prepend(y);
// x == "airship"
//! [15]


//! [16]
QByteArray x("free");
QByteArray y("dom");
x.append(y);
// x == "freedom"
//! [16]


//! [17]
QByteArray ba("Meal");
ba.insert(1, QByteArray("ontr"));
// ba == "Montreal"
//! [17]


//! [18]
QByteArray ba("Montreal");
ba.remove(1, 4);
// ba == "Meal"
//! [18]


//! [19]
QByteArray x("Say yes!");
QByteArray y("no");
x.replace(4, 3, y);
// x == "Say no!"
//! [19]


//! [20]
QByteArray ba("colour behaviour flavour neighbour");
ba.replace(QByteArray("ou"), QByteArray("o"));
// ba == "color behavior flavor neighbor"
//! [20]


//! [21]
QByteArray x("sticky question");
QByteArray y("sti");
x.indexOf(y);               // returns 0
x.indexOf(y, 1);            // returns 10
x.indexOf(y, 10);           // returns 10
x.indexOf(y, 11);           // returns -1
//! [21]


//! [22]
QByteArray ba("ABCBA");
ba.indexOf("B");            // returns 1
ba.indexOf("B", 1);         // returns 1
ba.indexOf("B", 2);         // returns 3
ba.indexOf("X");            // returns -1
//! [22]


//! [23]
QByteArray x("crazy azimuths");
QByteArray y("az");
x.lastIndexOf(y);           // returns 6
x.lastIndexOf(y, 6);        // returns 6
x.lastIndexOf(y, 5);        // returns 2
x.lastIndexOf(y, 1);        // returns -1
//! [23]


//! [24]
QByteArray ba("ABCBA");
ba.lastIndexOf("B");        // returns 3
ba.lastIndexOf("B", 3);     // returns 3
ba.lastIndexOf("B", 2);     // returns 1
ba.lastIndexOf("X");        // returns -1
//! [24]


//! [25]
QByteArray url("ftp://ftp.qt.nokia.com/");
if (url.startsWith("ftp:"))
    ...
//! [25]


//! [26]
QByteArray url("http://qt.nokia.com/index.html");
if (url.endsWith(".html"))
    ...
//! [26]


//! [27]
QByteArray x("Pineapple");
QByteArray y = x.left(4);
// y == "Pine"
//! [27]


//! [28]
QByteArray x("Pineapple");
QByteArray y = x.right(5);
// y == "apple"
//! [28]


//! [29]
QByteArray x("Five pineapples");
QByteArray y = x.mid(5, 4);     // y == "pine"
QByteArray z = x.mid(5);        // z == "pineapples"
//! [29]


//! [30]
QByteArray x("Qt by NOKIA");
QByteArray y = x.toLower();
// y == "qt by nokia"
//! [30]


//! [31]
QByteArray x("Qt by NOKIA");
QByteArray y = x.toUpper();
// y == "QT BY NOKIA"
//! [31]


//! [32]
QByteArray ba("  lots\t of\nwhitespace\r\n ");
ba = ba.simplified();
// ba == "lots of whitespace";
//! [32]


//! [33]
QByteArray ba("  lots\t of\nwhitespace\r\n ");
ba = ba.trimmed();
// ba == "lots\t of\nwhitespace";
//! [33]


//! [34]
QByteArray x("apple");
QByteArray y = x.leftJustified(8, '.');   // y == "apple..."
//! [34]


//! [35]
QByteArray x("apple");
QByteArray y = x.rightJustified(8, '.');    // y == "...apple"
//! [35]


//! [36]
QByteArray str("FF");
bool ok;
int hex = str.toInt(&ok, 16);     // hex == 255, ok == true
int dec = str.toInt(&ok, 10);     // dec == 0, ok == false
//! [36]


//! [37]
QByteArray str("FF");
bool ok;
long hex = str.toLong(&ok, 16);   // hex == 255, ok == true
long dec = str.toLong(&ok, 10);   // dec == 0, ok == false
//! [37]


//! [38]
QByteArray string("1234.56");
double a = string.toDouble();   // a == 1234.56
//! [38]


//! [39]
QByteArray text("Qt is great!");
text.toBase64();        // returns "UXQgaXMgZ3JlYXQh"
//! [39]


//! [40]
QByteArray ba;
int n = 63;
ba.setNum(n);           // ba == "63"
ba.setNum(n, 16);       // ba == "3f"
//! [40]


//! [41]
int n = 63;
QByteArray::number(n);              // returns "63"
QByteArray::number(n, 16);          // returns "3f"
QByteArray::number(n, 16).toUpper();  // returns "3F"
//! [41]


//! [42]
QByteArray ba = QByteArray::number(12.3456, 'E', 3);
// ba == 1.235E+01
//! [42]


//! [43]
 static const char mydata[] = {
    0x00, 0x00, 0x03, 0x84, 0x78, 0x9c, 0x3b, 0x76,
    0xec, 0x18, 0xc3, 0x31, 0x0a, 0xf1, 0xcc, 0x99,
    ...
    0x6d, 0x5b
};

QByteArray data = QByteArray::fromRawData(mydata, sizeof(mydata));
QDataStream in(&data, QIODevice::ReadOnly);
...
//! [43]


//! [44]
QByteArray text = QByteArray::fromBase64("UXQgaXMgZ3JlYXQh");
text.data();            // returns "Qt is great!"
//! [44]


//! [45]
QByteArray text = QByteArray::fromHex("517420697320677265617421");
text.data();            // returns "Qt is great!"
//! [45]

//! [46]
QString tmp = "test";
QByteArray text = tmp.toLocal8Bit();
char *data = new char[text.size()]
strcpy(data, text.data());
delete [] data; 
//! [46]

//! [47]
QString tmp = "test";
QByteArray text = tmp.toLocal8Bit();
char *data = new char[text.size() + 1]
strcpy(data, text.data());
delete [] data;
//! [47]

//! [48]
QByteArray ba1("ca\0r\0t");
ba1.size();                     // Returns 2.
ba1.constData();                // Returns "ca" with terminating \0.

QByteArray ba2("ca\0r\0t", 3);
ba2.size();                     // Returns 3.
ba2.constData();                // Returns "ca\0" with terminating \0.

QByteArray ba3("ca\0r\0t", 4);
ba3.size();                     // Returns 4.
ba2.constData();                // Returns "ca\0r" with terminating \0.

const char cart[] = {'c', 'a', '\0', 'r', '\0', 't'};
QByteArray ba4(QByteArray::fromRawData(cart, 6));
ba4.size();                     // Returns 6.
ba4.constData();                // Returns "ca\0r\0t" without terminating \0.
//! [48]

}
Beispiel #4
0
QT_BEGIN_NAMESPACE

MainWindow::MainWindow(CmdLineParser *cmdLine, QWidget *parent)
    : QMainWindow(parent)
    , m_bookmarkWidget(0)
    , m_filterCombo(0)
    , m_toolBarMenu(0)
    , m_cmdLine(cmdLine)
    , m_progressWidget(0)
    , m_qtDocInstaller(0)
    , m_connectedInitSignals(false)
{
    TRACE_OBJ

    setToolButtonStyle(Qt::ToolButtonFollowStyle);
    setDockOptions(dockOptions() | AllowNestedDocks);

    QString collectionFile;
    if (usesDefaultCollection()) {
        MainWindow::collectionFileDirectory(true);
        collectionFile = MainWindow::defaultHelpCollectionFileName();
    } else {
        collectionFile = cmdLine->collectionFile();
    }
    HelpEngineWrapper &helpEngineWrapper =
        HelpEngineWrapper::instance(collectionFile);
    BookmarkManager *bookMarkManager = BookmarkManager::instance();

    if (!initHelpDB(!cmdLine->collectionFileGiven())) {
        qDebug("Fatal error: Help engine initialization failed. "
            "Error message was: %s\nAssistant will now exit.",
            qPrintable(HelpEngineWrapper::instance().error()));
        std::exit(1);
    }

    m_centralWidget = new CentralWidget(this);
    setCentralWidget(m_centralWidget);

    m_indexWindow = new IndexWindow(this);
    QDockWidget *indexDock = new QDockWidget(tr("Index"), this);
    indexDock->setObjectName(QLatin1String("IndexWindow"));
    indexDock->setWidget(m_indexWindow);
    addDockWidget(Qt::LeftDockWidgetArea, indexDock);

    m_contentWindow = new ContentWindow;
    QDockWidget *contentDock = new QDockWidget(tr("Contents"), this);
    contentDock->setObjectName(QLatin1String("ContentWindow"));
    contentDock->setWidget(m_contentWindow);
    addDockWidget(Qt::LeftDockWidgetArea, contentDock);

    m_searchWindow = new SearchWidget(helpEngineWrapper.searchEngine());
    m_searchWindow->setFont(!helpEngineWrapper.usesBrowserFont() ? qApp->font()
        : helpEngineWrapper.browserFont());
    QDockWidget *searchDock = new QDockWidget(tr("Search"), this);
    searchDock->setObjectName(QLatin1String("SearchWindow"));
    searchDock->setWidget(m_searchWindow);
    addDockWidget(Qt::LeftDockWidgetArea, searchDock);

    QDockWidget *bookmarkDock = new QDockWidget(tr("Bookmarks"), this);
    bookmarkDock->setObjectName(QLatin1String("BookmarkWindow"));
    bookmarkDock->setWidget(m_bookmarkWidget
        = bookMarkManager->bookmarkDockWidget());
    addDockWidget(Qt::LeftDockWidgetArea, bookmarkDock);

    QDockWidget *openPagesDock = new QDockWidget(tr("Open Pages"), this);
    openPagesDock->setObjectName(QLatin1String("Open Pages"));
    OpenPagesManager *openPagesManager
        = OpenPagesManager::createInstance(this, usesDefaultCollection(), m_cmdLine->url());
    openPagesDock->setWidget(openPagesManager->openPagesWidget());
    addDockWidget(Qt::LeftDockWidgetArea, openPagesDock);

    connect(m_centralWidget, SIGNAL(addBookmark(QString, QString)),
        bookMarkManager, SLOT(addBookmark(QString, QString)));
    connect(bookMarkManager, SIGNAL(escapePressed()), this,
            SLOT(activateCurrentCentralWidgetTab()));
    connect(bookMarkManager, SIGNAL(setSource(QUrl)), m_centralWidget,
            SLOT(setSource(QUrl)));
    connect(bookMarkManager, SIGNAL(setSourceInNewTab(QUrl)),
        openPagesManager, SLOT(createPage(QUrl)));

    QHelpSearchEngine *searchEngine = helpEngineWrapper.searchEngine();
    connect(searchEngine, SIGNAL(indexingStarted()), this, SLOT(indexingStarted()));
    connect(searchEngine, SIGNAL(indexingFinished()), this, SLOT(indexingFinished()));

    QString defWindowTitle = tr("Qt Assistant");
    setWindowTitle(defWindowTitle);

    setupActions();
    statusBar()->show();
    m_centralWidget->connectTabBar();

    setupFilterToolbar();
    setupAddressToolbar();

    const QString windowTitle = helpEngineWrapper.windowTitle();
    setWindowTitle(windowTitle.isEmpty() ? defWindowTitle : windowTitle);
    QByteArray iconArray = helpEngineWrapper.applicationIcon();
    if (iconArray.size() > 0) {
        QPixmap pix;
        pix.loadFromData(iconArray);
        QIcon appIcon(pix);
        qApp->setWindowIcon(appIcon);
    } else {
        QIcon appIcon(QLatin1String(":/trolltech/assistant/images/assistant-128.png"));
        qApp->setWindowIcon(appIcon);
    }

    QToolBar *toolBar = addToolBar(tr("Bookmark Toolbar"));
    toolBar->setObjectName(QLatin1String("Bookmark Toolbar"));
    bookMarkManager->setBookmarksToolbar(toolBar);

    // Show the widget here, otherwise the restore geometry and state won't work
    // on x11.
    show();

    toolBar->hide();
    toolBarMenu()->addAction(toolBar->toggleViewAction());

    QByteArray ba(helpEngineWrapper.mainWindow());
    if (!ba.isEmpty())
        restoreState(ba);

    ba = helpEngineWrapper.mainWindowGeometry();
    if (!ba.isEmpty()) {
        restoreGeometry(ba);
    } else {
        tabifyDockWidget(contentDock, indexDock);
        tabifyDockWidget(indexDock, bookmarkDock);
        tabifyDockWidget(bookmarkDock, searchDock);
        contentDock->raise();
        const QRect screen = QApplication::desktop()->screenGeometry();
        resize(4*screen.width()/5, 4*screen.height()/5);
    }

    if (!helpEngineWrapper.hasFontSettings()) {
        helpEngineWrapper.setUseAppFont(false);
        helpEngineWrapper.setUseBrowserFont(false);
        helpEngineWrapper.setAppFont(qApp->font());
        helpEngineWrapper.setAppWritingSystem(QFontDatabase::Latin);
        helpEngineWrapper.setBrowserFont(qApp->font());
        helpEngineWrapper.setBrowserWritingSystem(QFontDatabase::Latin);
    } else {
        updateApplicationFont();
    }

    updateAboutMenuText();

    QTimer::singleShot(0, this, SLOT(insertLastPages()));
    if (m_cmdLine->enableRemoteControl())
        (void)new RemoteControl(this);

    if (m_cmdLine->contents() == CmdLineParser::Show)
        showContents();
    else if (m_cmdLine->contents() == CmdLineParser::Hide)
        hideContents();

    if (m_cmdLine->index() == CmdLineParser::Show)
        showIndex();
    else if (m_cmdLine->index() == CmdLineParser::Hide)
        hideIndex();

    if (m_cmdLine->bookmarks() == CmdLineParser::Show)
        showBookmarksDockWidget();
    else if (m_cmdLine->bookmarks() == CmdLineParser::Hide)
        hideBookmarksDockWidget();

    if (m_cmdLine->search() == CmdLineParser::Show)
        showSearch();
    else if (m_cmdLine->search() == CmdLineParser::Hide)
        hideSearch();

    if (m_cmdLine->contents() == CmdLineParser::Activate)
        showContents();
    else if (m_cmdLine->index() == CmdLineParser::Activate)
        showIndex();
    else if (m_cmdLine->bookmarks() == CmdLineParser::Activate)
        showBookmarksDockWidget();

    if (!m_cmdLine->currentFilter().isEmpty()) {
        const QString &curFilter = m_cmdLine->currentFilter();
        if (helpEngineWrapper.customFilters().contains(curFilter))
            helpEngineWrapper.setCurrentFilter(curFilter);
    }

    if (usesDefaultCollection())
        QTimer::singleShot(0, this, SLOT(lookForNewQtDocumentation()));
    else
        checkInitState();

    connect(&helpEngineWrapper, SIGNAL(documentationRemoved(QString)),
            this, SLOT(documentationRemoved(QString)));
    connect(&helpEngineWrapper, SIGNAL(documentationUpdated(QString)),
            this, SLOT(documentationUpdated(QString)));

    setTabPosition(Qt::AllDockWidgetAreas, QTabWidget::North);
    GlobalActions::instance()->updateActions();
    if (helpEngineWrapper.addressBarEnabled())
        showNewAddress();
}
bool parse_and_validate_tx_from_blob(const blobdata& tx_blob, Transaction& tx) {
  std::stringstream ss;
  ss << tx_blob;
  binary_archive<false> ba(ss);
  return ::serialization::serialize(ba, tx);
}
Beispiel #6
0
QString QIconvCodec::convertToUnicode(const char* chars, int len, ConverterState *convState) const
{
    if (utf16Codec == reinterpret_cast<QTextCodec *>(~0))
        return QString::fromLatin1(chars, len);

    int invalidCount = 0;
    int remainingCount = 0;
    char *remainingBuffer = 0;
    IconvState *temporaryState = 0;
    IconvState **pstate;

    if (convState) {
        // stateful conversion
        pstate = reinterpret_cast<IconvState **>(&convState->d);
        if (convState->d) {
            // restore state
            remainingCount = convState->remainingChars;
            remainingBuffer = (*pstate)->buffer;
        } else {
            // first time
            convState->flags |= FreeFunction;
            QTextCodecUnalignedPointer::encode(convState->state_data, qIconvCodecStateFree);
        }
    } else {
        QThreadStorage<QIconvCodec::IconvState *> *ts = toUnicodeState();
        if (!ts) {
            // we're running after the Q_GLOBAL_STATIC has been deleted
            // or before the QCoreApplication initialization
            // bad programmer, no cookie for you
            pstate = &temporaryState;
        } else {
            // stateless conversion -- use thread-local data
            pstate = &toUnicodeState()->localData();
        }
    }

    if (!*pstate) {
        // first time, create the state
        iconv_t cd = createIconv_t(UTF16, 0);
        if (cd == reinterpret_cast<iconv_t>(-1)) {
            static int reported = 0;
            if (!reported++) {
                fprintf(stderr,
                        "QIconvCodec::convertToUnicode: using Latin-1 for conversion, iconv_open failed\n");
            }
            return QString::fromLatin1(chars, len);
        }

        *pstate = new IconvState(cd);
    }

    IconvState *state = *pstate;
    size_t inBytesLeft = len;
    // best case assumption, each byte is converted into one UTF-16 character, plus 2 bytes for the BOM
#ifdef GNU_LIBICONV
    // GNU doesn't disagree with POSIX :/
    const char *inBytes = chars;
#else
    char *inBytes = const_cast<char *>(chars);
#endif

    QByteArray in;
    if (remainingCount) {
        // we have to prepend the remaining bytes from the previous conversion
        inBytesLeft += remainingCount;
        in.resize(inBytesLeft);
        inBytes = in.data();

        memcpy(in.data(), remainingBuffer, remainingCount);
        memcpy(in.data() + remainingCount, chars, len);

        remainingCount = 0;
    }

    size_t outBytesLeft = len * 2 + 2;
    QByteArray ba(outBytesLeft, Qt::Uninitialized);
    char *outBytes = ba.data();
    do {
        size_t ret = iconv(state->cd, &inBytes, &inBytesLeft, &outBytes, &outBytesLeft);
        if (ret == (size_t) -1) {
            if (errno == E2BIG) {
                int offset = ba.size() - outBytesLeft;
                ba.resize(ba.size() * 2);
                outBytes = ba.data() + offset;
                outBytesLeft = ba.size() - offset;

                continue;
            }

            if (errno == EILSEQ) {
                // conversion stopped because of an invalid character in the sequence
                ++invalidCount;
            } else if (errno == EINVAL && convState) {
                // conversion stopped because the remaining inBytesLeft make up
                // an incomplete multi-byte sequence; save them for later
                state->saveChars(inBytes, inBytesLeft);
                remainingCount = inBytesLeft;
                break;
            }

            if (errno == EILSEQ || errno == EINVAL) {
                // skip the next character
                ++inBytes;
                --inBytesLeft;
                continue;
            }

            // some other error
            // note, cannot use qWarning() since we are implementing the codecForLocale :)
            perror("QIconvCodec::convertToUnicode: using Latin-1 for conversion, iconv failed");

            if (!convState) {
                // reset state
                iconv(state->cd, 0, &inBytesLeft, 0, &outBytesLeft);
            }

            delete temporaryState;
            return QString::fromLatin1(chars, len);
        }
    } while (inBytesLeft != 0);

    QString s;

    if (convState) {
        s = utf16Codec->toUnicode(ba.constData(), ba.size() - outBytesLeft, &state->internalState);

        convState->invalidChars = invalidCount;
        convState->remainingChars = remainingCount;
    } else {
        s = utf16Codec->toUnicode(ba.constData(), ba.size() - outBytesLeft);

        // reset state
        iconv(state->cd, 0, &inBytesLeft, 0, &outBytesLeft);
    }

    delete temporaryState;
    return s;
}
Beispiel #7
0
QByteArray QIconvCodec::convertFromUnicode(const QChar *uc, int len, ConverterState *convState) const
{
    char *inBytes;
    char *outBytes;
    size_t inBytesLeft;

#if defined(GNU_LIBICONV)
    const char **inBytesPtr = const_cast<const char **>(&inBytes);
#else
    char **inBytesPtr = &inBytes;
#endif

    IconvState *temporaryState = 0;
    QThreadStorage<QIconvCodec::IconvState *> *ts = fromUnicodeState();
    IconvState *&state = ts ? ts->localData() : temporaryState;
    if (!state) {
        iconv_t cd = createIconv_t(0, UTF16);
        if (cd != reinterpret_cast<iconv_t>(-1)) {
            if (!setByteOrder(cd)) {
                perror("QIconvCodec::convertFromUnicode: using Latin-1 for conversion, iconv failed for BOM");

                iconv_close(cd);
                cd = reinterpret_cast<iconv_t>(-1);

                return QString(uc, len).toLatin1();
            }
        }
        state = new IconvState(cd);
    }
    if (state->cd == reinterpret_cast<iconv_t>(-1)) {
        static int reported = 0;
        if (!reported++) {
            fprintf(stderr,
                    "QIconvCodec::convertFromUnicode: using Latin-1 for conversion, iconv_open failed\n");
        }
        delete temporaryState;
        return QString(uc, len).toLatin1();
    }

    size_t outBytesLeft = len;
    QByteArray ba(outBytesLeft, Qt::Uninitialized);
    outBytes = ba.data();

    // now feed iconv() the real data
    inBytes = const_cast<char *>(reinterpret_cast<const char *>(uc));
    inBytesLeft = len * sizeof(QChar);

    QByteArray in;
    if (convState && convState->remainingChars) {
        // we have one surrogate char to be prepended
        in.resize(sizeof(QChar) + len);
        inBytes = in.data();

        QChar remaining = convState->state_data[0];
        memcpy(in.data(), &remaining, sizeof(QChar));
        memcpy(in.data() + sizeof(QChar), uc, inBytesLeft);

        inBytesLeft += sizeof(QChar);
        convState->remainingChars = 0;
    }

    int invalidCount = 0;
    while (inBytesLeft != 0) {
        if (iconv(state->cd, inBytesPtr, &inBytesLeft, &outBytes, &outBytesLeft) == (size_t) -1) {
            if (errno == EINVAL && convState) {
                // buffer ends in a surrogate
                Q_ASSERT(inBytesLeft == 2);
                convState->remainingChars = 1;
                convState->state_data[0] = uc[len - 1].unicode();
                break;
            }

            switch (errno) {
            case EILSEQ:
                ++invalidCount;
                // fall through
            case EINVAL:
                {
                    inBytes += sizeof(QChar);
                    inBytesLeft -= sizeof(QChar);
                    break;
                }
            case E2BIG:
                {
                    int offset = ba.size() - outBytesLeft;
                    ba.resize(ba.size() * 2);
                    outBytes = ba.data() + offset;
                    outBytesLeft = ba.size() - offset;
                    break;
                }
            default:
                {
                    // note, cannot use qWarning() since we are implementing the codecForLocale :)
                    perror("QIconvCodec::convertFromUnicode: using Latin-1 for conversion, iconv failed");

                    // reset to initial state
                    iconv(state->cd, 0, &inBytesLeft, 0, &outBytesLeft);

                    delete temporaryState;
                    return QString(uc, len).toLatin1();
                }
            }
        }
    }

    // reset to initial state
    iconv(state->cd, 0, &inBytesLeft, 0, &outBytesLeft);
    setByteOrder(state->cd);

    ba.resize(ba.size() - outBytesLeft);

    if (convState)
        convState->invalidChars = invalidCount;

    delete temporaryState;
    return ba;
}
Beispiel #8
0
QByteArray elm327_read() { QByteArray ba("486B10410C2ABC"); return ba; }
Beispiel #9
0
QVariant QPSQLResult::data(int i)
{
    if (i >= PQnfields(d->result)) {
        qWarning("QPSQLResult::data: column %d out of range", i);
        return QVariant();
    }
    int ptype = PQftype(d->result, i);
    QVariant::Type type = qDecodePSQLType(ptype);
    const char *val = PQgetvalue(d->result, at(), i);
    if (PQgetisnull(d->result, at(), i))
        return QVariant(type);
    switch (type) {
    case QVariant::Bool:
        return QVariant((bool)(val[0] == 't'));
    case QVariant::String:
        return d->driver->isUtf8 ? QString::fromUtf8(val) : QString::fromAscii(val);
    case QVariant::LongLong:
        if (val[0] == '-')
            return QString::fromLatin1(val).toLongLong();
        else
            return QString::fromLatin1(val).toULongLong();
    case QVariant::Int:
        return atoi(val);
    case QVariant::Double:
        if (ptype == QNUMERICOID) {
            if (numericalPrecisionPolicy() != QSql::HighPrecision) {
                QVariant retval;
                bool convert;
                double dbl=QString::fromAscii(val).toDouble(&convert);
                if (numericalPrecisionPolicy() == QSql::LowPrecisionInt64)
                    retval = (qlonglong)dbl;
                else if (numericalPrecisionPolicy() == QSql::LowPrecisionInt32)
                    retval = (int)dbl;
                else if (numericalPrecisionPolicy() == QSql::LowPrecisionDouble)
                    retval = dbl;
                if (!convert)
                    return QVariant();
                return retval;
            }
            return QString::fromAscii(val);
        }
        return QString::fromAscii(val).toDouble();
    case QVariant::Date:
        if (val[0] == '\0') {
            return QVariant(QDate());
        } else {
#ifndef QT_NO_DATESTRING
            return QVariant(QDate::fromString(QString::fromLatin1(val), Qt::ISODate));
#else
            return QVariant(QString::fromLatin1(val));
#endif
        }
    case QVariant::Time: {
        const QString str = QString::fromLatin1(val);
#ifndef QT_NO_DATESTRING
        if (str.isEmpty())
            return QVariant(QTime());
        if (str.at(str.length() - 3) == QLatin1Char('+') || str.at(str.length() - 3) == QLatin1Char('-'))
            // strip the timezone
            // TODO: fix this when timestamp support comes into QDateTime
            return QVariant(QTime::fromString(str.left(str.length() - 3), Qt::ISODate));
        return QVariant(QTime::fromString(str, Qt::ISODate));
#else
        return QVariant(str);
#endif
    }
    case QVariant::DateTime: {
        QString dtval = QString::fromLatin1(val);
#ifndef QT_NO_DATESTRING
        if (dtval.length() < 10)
            return QVariant(QDateTime());
        // remove the timezone
        // TODO: fix this when timestamp support comes into QDateTime
        if (dtval.at(dtval.length() - 3) == QLatin1Char('+') || dtval.at(dtval.length() - 3) == QLatin1Char('-'))
            dtval.chop(3);
        // milliseconds are sometimes returned with 2 digits only
        if (dtval.at(dtval.length() - 3).isPunct())
            dtval += QLatin1Char('0');
        if (dtval.isEmpty())
            return QVariant(QDateTime());
        else
            return QVariant(QDateTime::fromString(dtval, Qt::ISODate));
#else
        return QVariant(dtval);
#endif
    }
    case QVariant::ByteArray: {
        size_t len;
        unsigned char *data = PQunescapeBytea((unsigned char*)val, &len);
        QByteArray ba((const char*)data, len);
        qPQfreemem(data);
        return QVariant(ba);
    }
    default:
    case QVariant::Invalid:
        qWarning("QPSQLResult::data: unknown data type");
    }
    return QVariant();
}
Beispiel #10
0
QByteArray QInstaller::retrieveData(QFileDevice *in, qint64 size)
{
    QByteArray ba(size, '\0');
    QInstaller::blockingRead(in, ba.data(), size);
    return ba;
}
void TestEShortcutWing::buttons_data()
{
    QByteArray ba(data());

    /* Create columns for a QByteArray that is fed to EWing::parseData()
       on each row, the channel number to read and the value expected for
       that channel after each parseData() call. */
    QTest::addColumn<QByteArray> ("ba");
    QTest::addColumn<int> ("channel");
    QTest::addColumn<int> ("value");

    /* First test that the button state is read as OFF, then set the
       button's state ON in the byte array (simulating a UDP packet that
       has been read from the network) and read the value again. Low bit (0)
       means that the button is down, high bit (1) means it's up. */

    /*             ROW NAME     DATA   CH   VAL */
    QTest::newRow("Button 0") << ba << 0 << 0;
    ba[13] = 127; /* 0111 1111 */
    QTest::newRow("Button 0") << ba << 0 << 255;

    QTest::newRow("Button 1") << ba << 1 << 0;
    ba[13] = 191; /* 1011 1111 */
    QTest::newRow("Button 1") << ba << 1 << 255;

    QTest::newRow("Button 2") << ba << 2 << 0;
    ba[13] = 223; /* 1101 1111 */
    QTest::newRow("Button 2") << ba << 2 << 255;

    QTest::newRow("Button 3") << ba << 3 << 0;
    ba[13] = 239; /* 1110 1111 */
    QTest::newRow("Button 3") << ba << 3 << 255;

    QTest::newRow("Button 4") << ba << 4 << 0;
    ba[13] = 247; /* 1111 0111 */
    QTest::newRow("Button 4") << ba << 4 << 255;

    QTest::newRow("Button 5") << ba << 5 << 0;
    ba[13] = 251; /* 1111 1011 */
    QTest::newRow("Button 5") << ba << 5 << 255;

    QTest::newRow("Button 6") << ba << 6 << 0;
    ba[13] = 253; /* 1111 1101 */
    QTest::newRow("Button 6") << ba << 6 << 255;

    QTest::newRow("Button 7") << ba << 7 << 0;
    ba[13] = 254; /* 1111 1110 */
    QTest::newRow("Button 7") << ba << 7 << 255;

    QTest::newRow("Button 8") << ba << 8 << 0;
    ba[12] = 127; /* 0111 1111 */
    QTest::newRow("Button 8") << ba << 8 << 255;

    QTest::newRow("Button 9") << ba << 9 << 0;
    ba[12] = 191; /* 1011 1111 */
    QTest::newRow("Button 9") << ba << 9 << 255;

    QTest::newRow("Button 10") << ba << 10 << 0;
    ba[12] = 223; /* 1101 1111 */
    QTest::newRow("Button 10") << ba << 10 << 255;

    QTest::newRow("Button 11") << ba << 11 << 0;
    ba[12] = 239; /* 1110 1111 */
    QTest::newRow("Button 11") << ba << 11 << 255;

    QTest::newRow("Button 12") << ba << 12 << 0;
    ba[12] = 247; /* 1111 0111 */
    QTest::newRow("Button 12") << ba << 12 << 255;

    QTest::newRow("Button 13") << ba << 13 << 0;
    ba[12] = 251; /* 1111 1011 */
    QTest::newRow("Button 13") << ba << 13 << 255;

    QTest::newRow("Button 14") << ba << 14 << 0;
    ba[12] = 253; /* 1111 1101 */
    QTest::newRow("Button 14") << ba << 14 << 255;

    QTest::newRow("Button 15") << ba << 15 << 0;
    ba[12] = 254; /* 1111 1110 */
    QTest::newRow("Button 15") << ba << 15 << 255;

    QTest::newRow("Button 16") << ba << 16 << 0;
    ba[11] = 127; /* 0111 1111 */
    QTest::newRow("Button 16") << ba << 16 << 255;

    QTest::newRow("Button 17") << ba << 17 << 0;
    ba[11] = 191; /* 1011 1111 */
    QTest::newRow("Button 17") << ba << 17 << 255;

    QTest::newRow("Button 18") << ba << 18 << 0;
    ba[11] = 223; /* 1101 1111 */
    QTest::newRow("Button 18") << ba << 18 << 255;

    QTest::newRow("Button 19") << ba << 19 << 0;
    ba[11] = 239; /* 1110 1111 */
    QTest::newRow("Button 19") << ba << 19 << 255;

    QTest::newRow("Button 20") << ba << 20 << 0;
    ba[11] = 247; /* 1111 0111 */
    QTest::newRow("Button 20") << ba << 20 << 255;

    QTest::newRow("Button 21") << ba << 21 << 0;
    ba[11] = 251; /* 1111 1011 */
    QTest::newRow("Button 21") << ba << 21 << 255;

    QTest::newRow("Button 22") << ba << 22 << 0;
    ba[11] = 253; /* 1111 1101 */
    QTest::newRow("Button 22") << ba << 22 << 255;

    QTest::newRow("Button 23") << ba << 23 << 0;
    ba[11] = 254; /* 1111 1110 */
    QTest::newRow("Button 23") << ba << 23 << 255;

    QTest::newRow("Button 24") << ba << 24 << 0;
    ba[10] = 127; /* 0111 1111 */
    QTest::newRow("Button 24") << ba << 24 << 255;

    QTest::newRow("Button 25") << ba << 25 << 0;
    ba[10] = 191; /* 1011 1111 */
    QTest::newRow("Button 25") << ba << 25 << 255;

    QTest::newRow("Button 26") << ba << 26 << 0;
    ba[10] = 223; /* 1101 1111 */
    QTest::newRow("Button 26") << ba << 26 << 255;

    QTest::newRow("Button 27") << ba << 27 << 0;
    ba[10] = 239; /* 1110 1111 */
    QTest::newRow("Button 27") << ba << 27 << 255;

    QTest::newRow("Button 28") << ba << 28 << 0;
    ba[10] = 247; /* 1111 0111 */
    QTest::newRow("Button 28") << ba << 28 << 255;

    QTest::newRow("Button 29") << ba << 29 << 0;
    ba[10] = 251; /* 1111 1011 */
    QTest::newRow("Button 29") << ba << 29 << 255;

    QTest::newRow("Button 30") << ba << 30 << 0;
    ba[10] = 253; /* 1111 1101 */
    QTest::newRow("Button 30") << ba << 30 << 255;

    QTest::newRow("Button 31") << ba << 31 << 0;
    ba[10] = 254; /* 1111 1110 */
    QTest::newRow("Button 31") << ba << 31 << 255;

    QTest::newRow("Button 32") << ba << 32 << 0;
    ba[9] = 127; /* 0111 1111 */
    QTest::newRow("Button 32") << ba << 32 << 255;

    QTest::newRow("Button 33") << ba << 33 << 0;
    ba[9] = 191; /* 1011 1111 */
    QTest::newRow("Button 33") << ba << 33 << 255;

    QTest::newRow("Button 34") << ba << 34 << 0;
    ba[9] = 223; /* 1101 1111 */
    QTest::newRow("Button 34") << ba << 34 << 255;

    QTest::newRow("Button 35") << ba << 35 << 0;
    ba[9] = 239; /* 1110 1111 */
    QTest::newRow("Button 35") << ba << 35 << 255;

    QTest::newRow("Button 36") << ba << 36 << 0;
    ba[9] = 247; /* 1111 0111 */
    QTest::newRow("Button 36") << ba << 36 << 255;

    QTest::newRow("Button 37") << ba << 37 << 0;
    ba[9] = 251; /* 1111 1011 */
    QTest::newRow("Button 37") << ba << 37 << 255;

    QTest::newRow("Button 38") << ba << 38 << 0;
    ba[9] = 253; /* 1111 1101 */
    QTest::newRow("Button 38") << ba << 38 << 255;

    QTest::newRow("Button 39") << ba << 39 << 0;
    ba[9] = 254; /* 1111 1110 */
    QTest::newRow("Button 39") << ba << 39 << 255;

    QTest::newRow("Button 40") << ba << 40 << 0;
    ba[8] = 127; /* 0111 1111 */
    QTest::newRow("Button 40") << ba << 40 << 255;

    QTest::newRow("Button 41") << ba << 41 << 0;
    ba[8] = 191; /* 1011 1111 */
    QTest::newRow("Button 41") << ba << 41 << 255;

    QTest::newRow("Button 42") << ba << 42 << 0;
    ba[8] = 223; /* 1101 1111 */
    QTest::newRow("Button 42") << ba << 42 << 255;

    QTest::newRow("Button 43") << ba << 43 << 0;
    ba[8] = 239; /* 1110 1111 */
    QTest::newRow("Button 43") << ba << 43 << 255;

    QTest::newRow("Button 44") << ba << 44 << 0;
    ba[8] = 247; /* 1111 0111 */
    QTest::newRow("Button 44") << ba << 44 << 255;

    QTest::newRow("Button 45") << ba << 45 << 0;
    ba[8] = 251; /* 1111 1011 */
    QTest::newRow("Button 45") << ba << 45 << 255;

    QTest::newRow("Button 46") << ba << 46 << 0;
    ba[8] = 253; /* 1111 1101 */
    QTest::newRow("Button 46") << ba << 46 << 255;

    QTest::newRow("Button 47") << ba << 47 << 0;
    ba[8] = 254; /* 1111 1110 */
    QTest::newRow("Button 47") << ba << 47 << 255;

    QTest::newRow("Button 48") << ba << 48 << 0;
    ba[7] = 127; /* 0111 1111 */
    QTest::newRow("Button 48") << ba << 48 << 255;

    QTest::newRow("Button 49") << ba << 49 << 0;
    ba[7] = 191; /* 1011 1111 */
    QTest::newRow("Button 49") << ba << 49 << 255;

    QTest::newRow("Button 50") << ba << 50 << 0;
    ba[7] = 223; /* 1101 1111 */
    QTest::newRow("Button 50") << ba << 50 << 255;

    QTest::newRow("Button 51") << ba << 51 << 0;
    ba[7] = 239; /* 1110 1111 */
    QTest::newRow("Button 51") << ba << 51 << 255;

    QTest::newRow("Button 52") << ba << 52 << 0;
    ba[7] = 247; /* 1111 0111 */
    QTest::newRow("Button 52") << ba << 52 << 255;

    QTest::newRow("Button 53") << ba << 53 << 0;
    ba[7] = 251; /* 1111 1011 */
    QTest::newRow("Button 53") << ba << 53 << 255;

    QTest::newRow("Button 54") << ba << 54 << 0;
    ba[7] = 253; /* 1111 1101 */
    QTest::newRow("Button 54") << ba << 54 << 255;

    QTest::newRow("Button 55") << ba << 55 << 0;
    ba[7] = 254; /* 1111 1110 */
    QTest::newRow("Button 55") << ba << 55 << 255;

    QTest::newRow("Button 56") << ba << 56 << 0;
    ba[6] = 127; /* 0111 1111 */
    QTest::newRow("Button 56") << ba << 56 << 255;

    QTest::newRow("Button 57") << ba << 57 << 0;
    ba[6] = 191; /* 1011 1111 */
    QTest::newRow("Button 57") << ba << 57 << 255;

    QTest::newRow("Button 58") << ba << 58 << 0;
    ba[6] = 223; /* 1101 1111 */
    QTest::newRow("Button 58") << ba << 58 << 255;

    QTest::newRow("Button 59") << ba << 59 << 0;
    ba[6] = 239; /* 1110 1111 */
    QTest::newRow("Button 59") << ba << 59 << 255;
}
Beispiel #12
0
QByteArray QInstaller::retrieveByteArray(QFileDevice *in)
{
    QByteArray ba(QInstaller::retrieveInt64(in), '\0');
    QInstaller::blockingRead(in, ba.data(), ba.size());
    return ba;
}
void HalfedgeMesh::build(const vector<vector<Index> >& polygons,
                         const vector<Vector3D>& vertexPositions)
// This method initializes the halfedge data structure from a raw list of
// polygons, where each input polygon is specified as a list of vertex indices.
// The input must describe a manifold, oriented surface, where the orientation
// of a polygon is determined by the order of vertices in the list. Polygons
// must have at least three vertices.  Note that there are no special conditions
// on the vertex indices, i.e., they do not have to start at 0 or 1, nor does
// the collection of indices have to be contiguous.  Overall, this initializer
// is designed to be robust but perhaps not incredibly fast (though of course
// this does not affect the performance of the resulting data structure).  One
// could also implement faster initializers that handle important special cases
// (e.g., all triangles, or data that is known to be manifold). Since there are
// no strong conditions on the indices of polygons, we assume that the list of
// vertex positions is given in lexicographic order (i.e., that the lowest index
// appearing in any polygon corresponds to the first entry of the list of
// positions and so on).
{
  // define some types, to improve readability
  typedef vector<Index> IndexList;
  typedef IndexList::const_iterator IndexListCIter;
  typedef vector<IndexList> PolygonList;
  typedef PolygonList::const_iterator PolygonListCIter;
  typedef pair<Index, Index> IndexPair;  // ordered pair of vertex indices,
                                         // corresponding to an edge of an
                                         // oriented polygon

  // Clear any existing elements.
  halfedges.clear();
  vertices.clear();
  edges.clear();
  faces.clear();
  boundaries.clear();

  // Since the vertices in our halfedge mesh are stored in a linked list,
  // we will temporarily need to keep track of the correspondence between
  // indices of vertices in our input and pointers to vertices in the new
  // mesh (which otherwise can't be accessed by index).  Note that since
  // we're using a general-purpose map (rather than, say, a vector), we can
  // be a bit more flexible about the indexing scheme: input vertex indices
  // aren't required to be 0-based or 1-based; in fact, the set of indices
  // doesn't even have to be contiguous.  Taking advantage of this fact makes
  // our conversion a bit more robust to different types of input, including
  // data that comes from a subset of a full mesh.

  // maps a vertex index to the corresponding vertex
  map<Index, VertexIter> indexToVertex;

  // Also store the vertex degree, i.e., the number of polygons that use each
  // vertex; this information will be used to check that the mesh is manifold.
  map<VertexIter, Size> vertexDegree;

  // First, we do some basic sanity checks on the input.
  for (PolygonListCIter p = polygons.begin(); p != polygons.end(); p++) {
    if (p->size() < 3) {
      // Refuse to build the mesh if any of the polygons have fewer than three
      // vertices.(Note that if we omit this check the code will still
      // constructsomething fairlymeaningful for 1- and 2-point polygons, but
      // enforcing this stricterrequirementon the input will help simplify code
      // further downstream, since it canbe certainit doesn't have to check for
      // these rather degenerate cases.)
      cerr << "Error converting polygons to halfedge mesh: each polygon must "
              "have at least three vertices." << endl;
      exit(1);
    }

    // We want to count the number of distinct vertex indices in this
    // polygon, to make sure it's the same as the number of vertices
    // in the polygon---if they disagree, then the polygon is not valid
    // (or at least, for simplicity we don't handle polygons of this type!).
    set<Index> polygonIndices;

    // loop over polygon vertices
    for (IndexListCIter i = p->begin(); i != p->end(); i++) {
      polygonIndices.insert(*i);

      // allocate one vertex for each new index we encounter
      if (indexToVertex.find(*i) == indexToVertex.end()) {
        VertexIter v = newVertex();
        v->halfedge() =
            halfedges.end();  // this vertex doesn't yet point to any halfedge
        indexToVertex[*i] = v;
        vertexDegree[v] = 1;  // we've now seen this vertex only once
      } else {
        // keep track of the number of times we've seen this vertex
        vertexDegree[indexToVertex[*i]]++;
      }

    }  // end loop over polygon vertices

    // check that all vertices of the current polygon are distinct
    Size degree = p->size();  // number of vertices in this polygon
    if (polygonIndices.size() < degree) {
      cerr << "Error converting polygons to halfedge mesh: one of the input "
              "polygons does not have distinct vertices!" << endl;
      cerr << "(vertex indices:";
      for (IndexListCIter i = p->begin(); i != p->end(); i++) {
        cerr << " " << *i;
      }
      cerr << ")" << endl;
      exit(1);
    }  // end check that polygon vertices are distinct

  }  // end basic sanity checks on input

  // The number of vertices in the mesh is the
  // number of unique indices seen in the input.
  Size nVertices = indexToVertex.size();

  // The number of faces is just the number of polygons in the input.
  Size nFaces = polygons.size();
  faces.resize(nFaces);  // allocate storage for faces in our new mesh

  // We will store a map from ordered pairs of vertex indices to
  // the corresponding halfedge object in our new (halfedge) mesh;
  // this map gets constructed during the next loop over polygons.
  map<IndexPair, HalfedgeIter> pairToHalfedge;

  // Next, we actually build the halfedge connectivity by again looping over
  // polygons
  PolygonListCIter p;
  FaceIter f;
  for (p = polygons.begin(), f = faces.begin(); p != polygons.end(); p++, f++) {
    vector<HalfedgeIter> faceHalfedges;  // cyclically ordered list of the half
                                         // edges of this face
    Size degree = p->size();             // number of vertices in this polygon

    // loop over the halfedges of this face (equivalently, the ordered pairs of
    // consecutive vertices)
    for (Index i = 0; i < degree; i++) {
      Index a = (*p)[i];                 // current index
      Index b = (*p)[(i + 1) % degree];  // next index, in cyclic order
      IndexPair ab(a, b);
      HalfedgeIter hab;

      // check if this halfedge already exists; if so, we have a problem!
      if (pairToHalfedge.find(ab) != pairToHalfedge.end()) {
        cerr << "Error converting polygons to halfedge mesh: found multiple "
                "oriented edges with indices (" << a << ", " << b << ")."
             << endl;
        cerr << "This means that either (i) more than two faces contain this "
                "edge (hence the surface is nonmanifold), or" << endl;
        cerr << "(ii) there are exactly two faces containing this edge, but "
                "they have the same orientation (hence the surface is" << endl;
        cerr << "not consistently oriented." << endl;
        exit(1);
      } else  // otherwise, the halfedge hasn't been allocated yet
      {
        // so, we point this vertex pair to a new halfedge
        hab = newHalfedge();
        pairToHalfedge[ab] = hab;

        // link the new halfedge to its face
        hab->face() = f;
        hab->face()->halfedge() = hab;

        // also link it to its starting vertex
        hab->vertex() = indexToVertex[a];
        hab->vertex()->halfedge() = hab;

        // keep a list of halfedges in this face, so that we can later
        // link them together in a loop (via their "next" pointers)
        faceHalfedges.push_back(hab);
      }

      // Also, check if the twin of this halfedge has already been constructed
      // (during construction of a different face).  If so, link the twins
      // together and allocate their shared halfedge.  By the end of this pass
      // over polygons, the only halfedges that will not have a twin will hence
      // be those that sit along the domain boundary.
      IndexPair ba(b, a);
      map<IndexPair, HalfedgeIter>::iterator iba = pairToHalfedge.find(ba);
      if (iba != pairToHalfedge.end()) {
        HalfedgeIter hba = iba->second;

        // link the twins
        hab->twin() = hba;
        hba->twin() = hab;

        // allocate and link their edge
        EdgeIter e = newEdge();
        hab->edge() = e;
        hba->edge() = e;
        e->halfedge() = hab;
      } else { // If we didn't find a twin...
        // ...mark this halfedge as being twinless by pointing
        // it to the end of the list of halfedges. If it remains
        // twinless by the end of the current loop over polygons,
        // it will be linked to a boundary face in the next pass.
        hab->twin() = halfedges.end();
      }

    }  // end loop over the current polygon's halfedges

    // Now that all the halfedges of this face have been allocated,
    // we can link them together via their "next" pointers.
    for (Index i = 0; i < degree; i++) {
      Index j =
          (i + 1) % degree;  // index of the next halfedge, in cyclic order
      faceHalfedges[i]->next() = faceHalfedges[j];
    }

  }  // done building basic halfedge connectivity

  // For each vertex on the boundary, advance its halfedge pointer to one that
  // is also on the boundary.
  for (VertexIter v = verticesBegin(); v != verticesEnd(); v++) {
    // loop over halfedges around vertex
    HalfedgeIter h = v->halfedge();
    do {
      if (h->twin() == halfedges.end()) {
        v->halfedge() = h;
        break;
      }

      h = h->twin()->next();
    } while (h != v->halfedge());  // end loop over halfedges around vertex

  }  // done advancing halfedge pointers for boundary vertices

  // Next we construct new faces for each boundary component.
  for (HalfedgeIter h = halfedgesBegin(); h != halfedgesEnd();
       h++)  // loop over all halfedges
  {
    // Any halfedge that does not yet have a twin is on the boundary of the
    // domain. If we follow the boundary around long enough we will of course
    // eventually make a closed loop; we can represent this boundary loop by a
    // new face. To make clear the distinction between faces and boundary loops,
    // the boundary face will (i) have a flag indicating that it is a boundary
    // loop, and (ii) be stored in a list of boundaries, rather than the usual
    // list of faces.  The reason we need the both the flag *and* the separate
    // list is that faces are often accessed in two fundamentally different
    // ways: either by (i) local traversal of the neighborhood of some mesh
    // element using the halfedge structure, or (ii) global traversal of all
    // faces (or boundary loops).
    if (h->twin() == halfedges.end()) {
      FaceIter b = newBoundary();
      vector<HalfedgeIter> boundaryHalfedges;  // keep a list of halfedges along
                                               // the boundary, so we can link
                                               // them together

      // We now need to walk around the boundary, creating new
      // halfedges and edges along the boundary loop as we go.
      HalfedgeIter i = h;
      do {
        // create a twin, which becomes a halfedge of the boundary loop
        HalfedgeIter t = newHalfedge();
        boundaryHalfedges.push_back(
            t);  // keep a list of all boundary halfedges, in cyclic order
        i->twin() = t;
        t->twin() = i;
        t->face() = b;
        t->vertex() = i->next()->vertex();

        // create the shared edge
        EdgeIter e = newEdge();
        e->halfedge() = i;
        i->edge() = e;
        t->edge() = e;

        // Advance i to the next halfedge along the current boundary loop
        // by walking around its target vertex and stopping as soon as we
        // find a halfedge that does not yet have a twin defined.
        i = i->next();
        while (i != h &&  // we're done if we end up back at the beginning of
                          // the loop
               i->twin() != halfedges.end())  // otherwise, we're looking for
                                              // the next twinless halfedge
                                              // along the loop
        {
          i = i->twin();
          i = i->next();
        }
      } while (i != h);

      // The only pointers that still need to be set are the "next" pointers of
      // the twins; these we can set from the list of boundary halfedges, but we
      // must use the opposite order from the order in the list, since the
      // orientation of the boundary loop is opposite the orientation of the
      // halfedges "inside" the domain boundary.
      Size degree = boundaryHalfedges.size();
      for (Index p = 0; p < degree; p++) {
        Index q = (p - 1 + degree) % degree;
        boundaryHalfedges[p]->next() = boundaryHalfedges[q];
      }

    }  // end construction of one of the boundary loops

    // Note that even though we are looping over all halfedges, we will still
    // construct the appropriate number of boundary loops (and not, say, one
    // loop per boundary halfedge).  The reason is that as we continue to
    // iterate through halfedges, we check whether their twin has been assigned,
    // and since new twins may have been assigned earlier in this loop, we will
    // end up skipping many subsequent halfedges.

  }  // done adding "virtual" faces corresponding to boundary loops

  // To make later traversal of the mesh easier, we will now advance the
  // halfedge
  // associated with each vertex such that it refers to the *first* non-boundary
  // halfedge, rather than the last one.
  for (VertexIter v = verticesBegin(); v != verticesEnd(); v++) {
    v->halfedge() = v->halfedge()->twin()->next();
  }

  // Finally, we check that all vertices are manifold.
  for (VertexIter v = vertices.begin(); v != vertices.end(); v++) {
    // First check that this vertex is not a "floating" vertex;
    // if it is then we do not have a valid 2-manifold surface.
    if (v->halfedge() == halfedges.end()) {
      cerr << "Error converting polygons to halfedge mesh: some vertices are "
              "not referenced by any polygon." << endl;
      exit(1);
    }

    // Next, check that the number of halfedges emanating from this vertex in
    // our half edge data structure equals the number of polygons containing
    // this vertex, which we counted during our first pass over the mesh.  If
    // not, then our vertex is not a "fan" of polygons, but instead has some
    // other (nonmanifold) structure.
    Size count = 0;
    HalfedgeIter h = v->halfedge();
    do {
      if (!h->face()->isBoundary()) {
        count++;
      }
      h = h->twin()->next();
    } while (h != v->halfedge());

    if (count != vertexDegree[v]) {
      cerr << "Error converting polygons to halfedge mesh: at least one of the "
              "vertices is nonmanifold." << endl;
      exit(1);
    }
  }  // end loop over vertices

  // Now that we have the connectivity, we copy the list of vertex
  // positions into member variables of the individual vertices.
  if (vertexPositions.size() != vertices.size()) {
    cerr << "Error converting polygons to halfedge mesh: number of vertex "
            "positions is different from the number of distinct vertices!"
         << endl;
    cerr << "(number of positions in input: " << vertexPositions.size() << ")"
         << endl;
    cerr << "(  number of vertices in mesh: " << vertices.size() << ")" << endl;
    exit(1);
  }
  // Since an STL map internally sorts its keys, we can iterate over the map
  // from vertex indices to vertex iterators to visit our (input) vertices in
  // lexicographic order
  int i = 0;
  for (map<Index, VertexIter>::const_iterator e = indexToVertex.begin();
       e != indexToVertex.end(); e++) {
    // grab a pointer to the vertex associated with the current key (i.e., the
    // current index)
    VertexIter v = e->second;

    // set the att of this vertex to the corresponding
    // position in the input
    v->position = vertexPositions[i];
    i++;
  }

  // compute initial normals
  for (VertexIter v = verticesBegin(); v != verticesEnd(); v++) {
    v->computeNormal();
  }

}  // end HalfedgeMesh::build()
Beispiel #14
0
void PGMNetwork::doWork()
{
    /* dispatch loop */
#ifndef _WIN32
    int fds;
    fd_set readfds;


#else
    SOCKET recv_sock, pending_sock;
    DWORD cEvents = PGM_RECV_SOCKET_READ_COUNT + 1;
    WSAEVENT waitEvents[ PGM_RECV_SOCKET_READ_COUNT + 1 ];
    socklen_t socklen = sizeof (SOCKET);

    waitEvents[0] = terminateEvent;
    waitEvents[1] = WSACreateEvent();
    waitEvents[2] = WSACreateEvent();
    assert (2 == PGM_RECV_SOCKET_READ_COUNT);
    pgm_getsockopt (sock, IPPROTO_PGM, PGM_RECV_SOCK, &recv_sock, &socklen);
    WSAEventSelect (recv_sock, waitEvents[1], FD_READ);
    pgm_getsockopt (sock, IPPROTO_PGM, PGM_PENDING_SOCK, &pending_sock, &socklen);
    WSAEventSelect (pending_sock, waitEvents[2], FD_READ);

    static WSAEVENT		terminateEvent;
#endif /* !_WIN32 */

    pgm_error_t* pgm_err = NULL;
    struct timeval tv;
    tv.tv_sec = 1;
    tv.tv_usec = 0;

    qDebug() << "Entering PGM message loop..." << QThread::currentThreadId();

    do {

#ifdef _WIN32
        DWORD dwTimeout, dwEvents;
#endif
        char buffer[4096];
        size_t len;
        struct pgm_sockaddr_t from;
        socklen_t fromlen = sizeof (from);
        const int status = pgm_recvfrom (m_socket,
                                         buffer,
                                         4096,
                                         0,
                                         &len,
                                         &from,
                                         &fromlen,
                                         &pgm_err);
        switch (status) {
        case PGM_IO_STATUS_NORMAL:
        {
            QByteArray ba(buffer, len);
            emit rx(ba);

            break;
        }
        case PGM_IO_STATUS_TIMER_PENDING:
        {
            socklen_t optlen = sizeof (tv);
            pgm_getsockopt (m_socket, IPPROTO_PGM, PGM_TIME_REMAIN, &tv, &optlen);
        }
            goto block;
        case PGM_IO_STATUS_RATE_LIMITED:
        {
            socklen_t optlen = sizeof (tv);
            pgm_getsockopt (m_socket, IPPROTO_PGM, PGM_RATE_REMAIN, &tv, &optlen);
        }
        case PGM_IO_STATUS_WOULD_BLOCK:
            /* select for next event */
block:
#ifndef _WIN32
            fds = m_terminate_pipe[0] + 1;
            FD_ZERO(&readfds);
            FD_SET(m_terminate_pipe[0], &readfds);
            pgm_select_info (m_socket, &readfds, NULL, &fds);
            fds = select (fds, &readfds, NULL, NULL, PGM_IO_STATUS_WOULD_BLOCK == status ? NULL : &tv);
#else
            dwTimeout = PGM_IO_STATUS_WOULD_BLOCK == status ? WSA_INFINITE : (DWORD)((tv.tv_sec * 1000) + (tv.tv_usec / 1000));
            dwEvents = WSAWaitForMultipleEvents (cEvents, waitEvents, FALSE, dwTimeout, FALSE);
            switch (dwEvents) {
            case WSA_WAIT_EVENT_0+1: WSAResetEvent (waitEvents[1]); break;
            case WSA_WAIT_EVENT_0+2: WSAResetEvent (waitEvents[2]); break;
            default: break;
            }
#endif /* !_WIN32 */
            break;

        default:
            if (pgm_err) {
                qDebug() << "pgm error:" << pgm_err->message;
                pgm_error_free (pgm_err);
                pgm_err = NULL;
            }
            if (PGM_IO_STATUS_ERROR == status)
                break;
        }

        QCoreApplication::processEvents();
    } while (!m_is_terminated);

    qDebug() << "Message loop terminated, cleaning up.";

    /* cleanup */
#ifndef _WIN32
    close (m_terminate_pipe[0]);
    close (m_terminate_pipe[1]);
#else
    WSACloseEvent (waitEvents[0]);
    WSACloseEvent (waitEvents[1]);
    WSACloseEvent (waitEvents[2]);
#endif /* !_WIN32 */

    this->thread()->quit();
}
NS_IMETHODIMP
nsDragService::SetupDragSession(
                                nsISupportsArray *aTransferables,
                                PRUint32 aActionType)
{
    PRUint32 itemCount = 0;
    aTransferables->Count(&itemCount);
    if (0 == itemCount)
    {
        NS_WARNING("No items to drag?");
        return NS_ERROR_FAILURE;
    }

    if (1 != itemCount)
    {
        NS_WARNING("Dragging more than one item, cannot do (yet?)");
        return NS_ERROR_NOT_IMPLEMENTED;
    }

    SetDropActionType(aActionType);

    QMimeData *mimeData = new QMimeData;

    nsCOMPtr<nsISupports> genericItem;
    aTransferables->GetElementAt(0, getter_AddRefs(genericItem));
    nsCOMPtr<nsITransferable> transferable(do_QueryInterface(genericItem));

    if (transferable)
    {
        nsCOMPtr <nsISupportsArray> flavorList;
        transferable->FlavorsTransferableCanExport(getter_AddRefs(flavorList));

        if (flavorList)
        {
            PRUint32 flavorCount;
            flavorList->Count( &flavorCount );

            for (PRUint32 flavor=0; flavor < flavorCount; flavor++)
            {
                nsCOMPtr<nsISupports> genericWrapper;
                flavorList->GetElementAt(flavor, getter_AddRefs(genericWrapper));
                nsCOMPtr<nsISupportsCString> currentFlavor;
                currentFlavor = do_QueryInterface(genericWrapper);

                if (currentFlavor)
                {
                    nsCOMPtr<nsISupports> data;
                    PRUint32 dataLen = 0;
                    nsXPIDLCString flavorStr;
                    currentFlavor->ToString(getter_Copies(flavorStr));

                    // Is it some flavor we think we could support?
                    if (!strcmp(kURLMime, flavorStr.get())
                     || !strcmp(kURLDataMime, flavorStr.get())
                     || !strcmp(kURLDescriptionMime, flavorStr.get())
                     || !strcmp(kHTMLMime, flavorStr.get())
                     || !strcmp(kUnicodeMime, flavorStr.get())
                        )
                    {
                        transferable->GetTransferData(flavorStr,getter_AddRefs(data),&dataLen);

                        nsCOMPtr<nsISupportsString> wideString;
                        wideString = do_QueryInterface(data);
                        if (!wideString)
                        {
                            return NS_ERROR_FAILURE;
                        }

                        nsAutoString utf16string;
                        wideString->GetData(utf16string);
                        QByteArray ba((const char*) utf16string.get(), dataLen);

                        mimeData->setData(flavorStr.get(), ba);
                    }
                }
            }
        }
    }

    if (qApp->thread() != QThread::currentThread()) {
        NS_WARNING("Cannot initialize drag session in non main thread");
        return NS_OK;
    }

    if (!mHiddenWidget) {
      mHiddenWidget = new QWidget();
    }
    mDrag = new QDrag( mHiddenWidget ); // TODO: Better drag source here?
    mDrag->setMimeData(mimeData);

    // mDrag and mimeData SHOULD NOT be destroyed. They are destroyed by QT.

    return NS_OK;
}
Beispiel #16
0
int
main (int argc, char** argv)
{
  BoxLib::Initialize(argc, argv);

  BL_PROFILE_VAR("main()", pmain);

  Array<DistributionMapping::Strategy> dmStrategies(nStrategies);
  dmStrategies[0] = DistributionMapping::ROUNDROBIN;
  dmStrategies[1] = DistributionMapping::KNAPSACK;
  dmStrategies[2] = DistributionMapping::SFC;
  dmStrategies[3] = DistributionMapping::PFC;

  Array<std::string> dmSNames(nStrategies);
  dmSNames[0] = "ROUNDROBIN";
  dmSNames[1] = "KNAPSACK";
  dmSNames[2] = "SFC";
  dmSNames[3] = "PFC";

  Array<double> dmSTimes(nStrategies, 0.0);

  for(int iS(0); iS < nStrategies * nTimes; ++iS) {

    int whichStrategy(iS % nStrategies);

    DistributionMapping::strategy(dmStrategies[whichStrategy]);

//    Box bx(IntVect(0,0,0),IntVect(511,511,255));
//    Box bx(IntVect(0,0,0),IntVect(1023,1023,255));
    Box bx(IntVect(0,0,0),IntVect(1023,1023,1023));
//    Box bx(IntVect(0,0,0),IntVect(2047,2047,1023));
//    Box bx(IntVect(0,0,0),IntVect(127,127,127));
//    Box bx(IntVect(0,0,0),IntVect(255,255,255));

    BoxArray ba(bx);
    ba.maxSize(64);

    const int N = 2000;  // This should be divisible by 4 !!!

    if (ParallelDescriptor::IOProcessor() && iS == 0) {
        std::cout << "Domain: " << bx << "  # boxes in BoxArray:  " << ba.size() << '\n';
    }
    if (ParallelDescriptor::IOProcessor())
        std::cout << "Strategy: " << dmSNames[DistributionMapping::strategy()] << '\n';


    ParallelDescriptor::Barrier();

    {
        //
        // A test of FillBoundary() on 1 grow cell with cross stencil.
        //
        MultiFab mf(ba,1,1); mf.setVal(1.23);

        ParallelDescriptor::Barrier();
        double beg = ParallelDescriptor::second();
        for (int i = 0; i < N; i++)
            mf.FillBoundary(true);
        double end = (ParallelDescriptor::second() - beg);

        ParallelDescriptor::ReduceRealMax(end,ParallelDescriptor::IOProcessorNumber());
        if (ParallelDescriptor::IOProcessor()) {
          std::cout << N << " cross x 1: " << end << std::endl;
	  dmSTimes[whichStrategy] += end;
	}
    }


    {
        //
        // A test of FillBoundary() on 1 grow cell with dense stencil.
        //
        MultiFab mf(ba,1,1); mf.setVal(1.23);

        ParallelDescriptor::Barrier();
        double beg = ParallelDescriptor::second();
        for (int i = 0; i < N; i++)
            mf.FillBoundary(false);
        double end = (ParallelDescriptor::second() - beg);

        ParallelDescriptor::ReduceRealMax(end,ParallelDescriptor::IOProcessorNumber());
        if (ParallelDescriptor::IOProcessor()) {
          std::cout << N << " dense x 1: " << end << std::endl;
	  dmSTimes[whichStrategy] += end;
	}
    }

    {
        //
        // First a test of FillBoundary() on 2 grow cells with dense stencil.
        //
        MultiFab mf(ba,1,2); mf.setVal(1.23);

        ParallelDescriptor::Barrier();
        double beg = ParallelDescriptor::second();
        for (int i = 0; i < N/2; i++)
            mf.FillBoundary(false);
        double end = (ParallelDescriptor::second() - beg);

        ParallelDescriptor::ReduceRealMax(end,ParallelDescriptor::IOProcessorNumber());
        if (ParallelDescriptor::IOProcessor()) {
          std::cout << (N/2) << " dense x 2: " << end << std::endl;
	  dmSTimes[whichStrategy] += end;
	}
    }

    {
        //
        // First a test of FillBoundary() on 4 grow cells with dense stencil.
        //
        MultiFab mf(ba,1,4); mf.setVal(1.23);

        ParallelDescriptor::Barrier();
        double beg = ParallelDescriptor::second();
        for (int i = 0; i < N/4; i++)
            mf.FillBoundary(false);
        double end = (ParallelDescriptor::second() - beg);

        ParallelDescriptor::ReduceRealMax(end,ParallelDescriptor::IOProcessorNumber());
        if (ParallelDescriptor::IOProcessor()) {
          std::cout << (N/4) << " dense x 4: " << end << std::endl;
	  dmSTimes[whichStrategy] += end;
	}
    }
    if (ParallelDescriptor::IOProcessor())
        std::cout << std::endl;

  }  // end for iS


    if(ParallelDescriptor::IOProcessor()) {
      for(int i(0); i < nStrategies; ++i) {
        std::cout << std::endl << "Total times:" << std::endl;
	std::cout << dmSNames[i] << " time = " << dmSTimes[i] << std::endl;
      }
      std::cout << std::endl << std::endl;
    }

    BL_PROFILE_VAR_STOP(pmain);

    BoxLib::Finalize();

    return 0;
}