示例#1
0
bool EQPacketOPCodeDB::save(const QString& filename)
{
  // create QFile object
  QFile file(filename);

  // open the file for write only
  if (!file.open(IO_WriteOnly))
    return false;

  // create a QTextStream object on the QFile object
  QTextStream out(&file);
  
  // set the output encoding to be UTF8
  out.setEncoding(QTextStream::UnicodeUTF8);

  // set the number output to be left justified decimal
  out.setf(QTextStream::dec | QTextStream::left);

  // print document header
  out << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << endl
      << "<!DOCTYPE seqopcodes SYSTEM \"seqopcodes.dtd\">" << endl
      << "<seqopcodes>" << endl;

  // set initial indent
  QString indent = "    ";

  EQPacketOPCode* currentOPCode;
  EQPacketPayload* currentPayload;

  typedef std::map<long, EQPacketOPCode*> OrderedMap;
  OrderedMap orderedOPCodes;

  // iterate over all the opcodes, inserting them into the ordered map
  QIntDictIterator<EQPacketOPCode> it(m_opcodes);
  while ((currentOPCode = it.current()) != NULL)
  {
    // insert into the ordered opcode map
    orderedOPCodes.insert(OrderedMap::value_type(currentOPCode->opcode(), 
						 currentOPCode));

    // get next opcode
    ++it;
  }

  OrderedMap::iterator oit;
  QCString opcodeString(256);
  static const char* dirStrs[] = { "client", "server", "both", };
  static const char* sztStrs[] = { "none", "match", "modulus", };

  // iterate over the ordered opcode map
  for (oit = orderedOPCodes.begin(); oit != orderedOPCodes.end(); ++oit)
  {
    currentOPCode = oit->second;

    // output the current opcode
    opcodeString.sprintf("%04x", currentOPCode->opcode());
    out << indent << "<opcode id=\"" << opcodeString << "\" name=\""
	<< currentOPCode->name() << "\"";
    if (currentOPCode->implicitLen())
      out << " implicitlen=\"" << currentOPCode->implicitLen() << "\"";
    if (!currentOPCode->updated().isEmpty())
      out << " updated=\"" << currentOPCode->updated() << "\"";
    out << ">" << endl;

    // increase the indent
    indent += "    ";

    // output the comments
    QStringList comments = currentOPCode->comments();
    for (QStringList::Iterator cit = comments.begin(); 
	 cit != comments.end(); ++cit)
      out << indent << "<comment>" << *cit << "</comment>" << endl;

    QCString dirStr;
    QCString sztStr;

    // iterate over the payloads
    QPtrListIterator<EQPacketPayload> pit(*currentOPCode);
    while ((currentPayload = pit.current()) != 0)
    {
      // output the payload
      out << indent << "<payload dir=\"" << dirStrs[currentPayload->dir()-1]
	  << "\" typename=\"" << currentPayload->typeName() 
	  << "\" sizechecktype=\""
	  << sztStrs[currentPayload->sizeCheckType()]
	  << "\"/>" << endl;

      ++pit;
    }

    // decrease the indent
    indent.remove(0, 4);

    // close the opcode entity
    out << indent << "</opcode>" << endl;
  }

  // output closing entity
  out << "</seqopcodes>" << endl;

  return true;
}
示例#2
0
int main(int argc, char **argv)
{
    int itemCount = 0;
    bool ok = false;

    if (argc > 1) {
        itemCount = QString(argv[1]).toInt(&ok);
        if (!ok) {
            qWarning() << "\nError! Enter a valid number.";
            qDebug() << "\nUsage:\n\t" << *argv << "<number of items for testing>\n";
            return 1;
        }
    } else {
        qDebug() << "\nUsage:\n\t" << *argv << "<number of items for testing>\n";
        return 1;
    }

    QMap<int, QString> map;
    QHash<int, QString> hash;
    QLinkedList<QString> linkList;

    OrderedMap<int, QString> om;

    QTime timer;

    qDebug() << "Timing insertion of" << itemCount << "items...\n";

    timer.start();
    for (int i=0; i<itemCount; i++) {
        map.insert(i, QString::number(i));
    }
    qDebug() << "Map :" << timer.elapsed() << "msecs";

    timer.start();
    for (int i=0; i<itemCount; i++) {
        hash.insert(i, QString::number(i));
    }
    qDebug() << "Hash :" << timer.elapsed() << "msecs";

    timer.start();
    for (int i=0; i<itemCount; i++) {
        linkList.append(QString::number(i));
    }
    qDebug() << "Link list :" << timer.elapsed() << "msecs";

    timer.start();
    for (int i=0; i<itemCount; i++) {
        om.insert(i, QString::number(i));
    }
    qDebug() << "Ordered ma :" << timer.elapsed() << "msecs";
    qDebug() << "\n";

    qDebug() << "Timing iteration over" << itemCount << "items...\n";

    int dummy = 0;
    timer.start();
    foreach (const QString& val, map.values()) {
        dummy += val.size();
    }
    qDebug() << "Map :" << timer.elapsed() << "msecs";

    dummy = 0;
    timer.start();
    foreach (const QString& val, hash.values()) {
        dummy += val.size();
    }
    qDebug() << "Hash :" << timer.elapsed() << "msecs";

    dummy = 0;
    timer.start();
    foreach (const QString& val, linkList) {
        dummy += val.size();
    }
    qDebug() << "Linked list :" << timer.elapsed() << "msecs";

    dummy = 0;
    timer.start();
    foreach (const QString& val, om.values()) {
        dummy += val.size();
    }
    qDebug() << "Ordered map :" << timer.elapsed() << "msecs";
    qDebug() << "\n";

    qDebug() << "Timing removal of random item from" << itemCount << "items...\n";

    int rand = qrand() % itemCount;
    timer.start();
    map.remove(rand);
    qDebug() << "Map :" << timer.elapsed() << "msecs";

    rand = qrand() % itemCount;
    timer.start();
    hash.remove(rand);
    qDebug() << "Hash :" << timer.elapsed() << "msecs";

    rand = qrand() % itemCount;
    timer.start();
    linkList.removeOne(QString::number(rand));
    qDebug() << "Link list :" << timer.elapsed() << "msecs";

    rand = qrand() % itemCount;
    timer.start();
    om.remove(rand);
    qDebug() << "Ordered map :" << timer.elapsed() << "msecs";
    qDebug() << "\n";

    return 0;
}