コード例 #1
0
ファイル: nocontext.cpp プロジェクト: twareproj/tware
int main(int argc, char *argv[]) {
    struct timeval start, stop;
    vector<vector<double> > times;
    for (int i = 0; i < DLEN; i++)
        times.push_back(vector<double>());

    int *test = new int();
    for (int i = DMIN; i < DMAX; i++) {
        int size = 1 << i;
        for (int j = 0; j < ITER; j++) {
            int *data = new int[size];
            unordered_map<int,int> *counts = new unordered_map<int,int>();
            init(data, size);

            gettimeofday(&start, NULL);
            int total = 0;
            for (int k = 0; k < size; k++)
                (*counts)[data[k]]++;
            gettimeofday(&stop, NULL);
            times[i - DMIN].push_back(getTime(start, stop));

            for (int k = 0; k < KEYS; k++)
                *test += (*counts)[k];
            delete[] data;
            delete counts;
        }
    }
    delete test;

    writeTimes(argv[1], times);
    return 0;
}
コード例 #2
0
ファイル: tiled.cpp プロジェクト: twareproj/tware
int main(int argc, char *argv[]) {
    struct timeval start, stop;
    vector<vector<double> > times;
    for (int i = 0; i < DLEN; i++)
        times.push_back(vector<double>());

    int *test = new int();
    for (int i = DMIN; i < DMAX; i++) {
        int size = 1 << i;
        for (int j = 0; j < ITER; j++) {
            float *data1 = new float[size];
            float *data2 = new float[size];
            float *result = new float[size];
            initNeg(data1, data2, size, 10);

            int batch = size / CACHE;
            float *temp1 = new float[CACHE];
            float *temp2 = new float[CACHE];

            gettimeofday(&start, NULL);
            for (int k = 0; k < batch; k++) {
                int curr = k * CACHE;
                for (int l = 0; l < CACHE; l++) {
                    int pos = curr + l;
                    temp1[l] = data1[pos];
                    if (temp1[l] < 0)
                        temp1[l] *= -1;
                    temp2[l] = data2[pos];
                    if (temp2[l] < 0)
                        temp2[l] *= -1;
                }
                for (int l = 0; l < CACHE; l++) {
                    int pos = curr + l;
                    result[pos] = temp1[l] + temp2[l];
                }
            }
            gettimeofday(&stop, NULL);
            times[i - DMIN].push_back(getTime(start, stop));

            *test += result[0];
            delete[] data1;
            delete[] data2;
            delete[] result;
            delete[] temp1;
            delete[] temp2;
        }
    }
    delete test;

    writeTimes("tiled", times);
    return 0;
}
コード例 #3
0
void KdbxXmlWriter::writeGroup(const Group* group)
{
    Q_ASSERT(!group->uuid().isNull());

    m_xml.writeStartElement("Group");

    writeUuid("UUID", group->uuid());
    writeString("Name", group->name());
    writeString("Notes", group->notes());
    writeNumber("IconID", group->iconNumber());

    if (!group->iconUuid().isNull()) {
        writeUuid("CustomIconUUID", group->iconUuid());
    }
    writeTimes(group->timeInfo());
    writeBool("IsExpanded", group->isExpanded());
    writeString("DefaultAutoTypeSequence", group->defaultAutoTypeSequence());

    writeTriState("EnableAutoType", group->autoTypeEnabled());

    writeTriState("EnableSearching", group->searchingEnabled());

    writeUuid("LastTopVisibleEntry", group->lastTopVisibleEntry());

    if (m_kdbxVersion >= KeePass2::FILE_VERSION_4) {
        writeCustomData(group->customData());
    }

    const QList<Entry*>& entryList = group->entries();
    for (const Entry* entry : entryList) {
        writeEntry(entry);
    }

    const QList<Group*>& children = group->children();
    for (const Group* child : children) {
        writeGroup(child);
    }

    m_xml.writeEndElement();
}
コード例 #4
0
void KdbxXmlWriter::writeEntry(const Entry* entry)
{
    Q_ASSERT(!entry->uuid().isNull());

    m_xml.writeStartElement("Entry");

    writeUuid("UUID", entry->uuid());
    writeNumber("IconID", entry->iconNumber());
    if (!entry->iconUuid().isNull()) {
        writeUuid("CustomIconUUID", entry->iconUuid());
    }
    writeColor("ForegroundColor", entry->foregroundColor());
    writeColor("BackgroundColor", entry->backgroundColor());
    writeString("OverrideURL", entry->overrideUrl());
    writeString("Tags", entry->tags());
    writeTimes(entry->timeInfo());

    const QList<QString> attributesKeyList = entry->attributes()->keys();
    for (const QString& key : attributesKeyList) {
        m_xml.writeStartElement("String");

        // clang-format off
        bool protect =
            (((key == "Title") && m_meta->protectTitle()) || ((key == "UserName") && m_meta->protectUsername())
            || ((key == "Password") && m_meta->protectPassword())
            || ((key == "URL") && m_meta->protectUrl())
            || ((key == "Notes") && m_meta->protectNotes())
            || entry->attributes()->isProtected(key));
        // clang-format on

        writeString("Key", key);

        m_xml.writeStartElement("Value");
        QString value;

        if (protect) {
            if (!m_innerStreamProtectionDisabled && m_randomStream) {
                m_xml.writeAttribute("Protected", "True");
                bool ok;
                QByteArray rawData = m_randomStream->process(entry->attributes()->value(key).toUtf8(), &ok);
                if (!ok) {
                    raiseError(m_randomStream->errorString());
                }
                value = QString::fromLatin1(rawData.toBase64());
            } else {
                m_xml.writeAttribute("ProtectInMemory", "True");
                value = entry->attributes()->value(key);
            }
        } else {
            value = entry->attributes()->value(key);
        }

        if (!value.isEmpty()) {
            m_xml.writeCharacters(stripInvalidXml10Chars(value));
        }
        m_xml.writeEndElement();

        m_xml.writeEndElement();
    }

    const QList<QString> attachmentsKeyList = entry->attachments()->keys();
    for (const QString& key : attachmentsKeyList) {
        m_xml.writeStartElement("Binary");

        writeString("Key", key);

        m_xml.writeStartElement("Value");
        m_xml.writeAttribute("Ref", QString::number(m_idMap[entry->attachments()->value(key)]));
        m_xml.writeEndElement();

        m_xml.writeEndElement();
    }

    writeAutoType(entry);

    if (m_kdbxVersion >= KeePass2::FILE_VERSION_4) {
        writeCustomData(entry->customData());
    }

    // write history only for entries that are not history items
    if (entry->parent()) {
        writeEntryHistory(entry);
    }

    m_xml.writeEndElement();
}
コード例 #5
0
ファイル: Arome.cpp プロジェクト: WFRT/gridpp
void FileArome::writeCore(std::vector<Variable::Type> iVariables) {
   writeTimes();
   writeReferenceTime();
   writeGlobalAttributes();
   for(int v = 0; v < iVariables.size(); v++) {
      Variable::Type varType = iVariables[v];
      std::string variable = getVariableName(varType);
      NcVar* var;
      if(hasVariableCore(varType)) {
         var = getVar(variable);
      }
      else {
         // Create variable
         if(0) {
            NcDim* dTime    = getDim("time");
            NcDim* dSurface = getDim("height0");
            NcDim* dLon     = getDim("x");
            NcDim* dLat     = getDim("y");
            var = mFile.add_var(variable.c_str(), ncFloat, dTime, dSurface, dLat, dLon);
         }
         else {
            NcDim* dTime    = getDim("time");
            NcDim* dLon     = getDim("x");
            NcDim* dLat     = getDim("y");
            var = mFile.add_var(variable.c_str(), ncFloat, dTime, dLat, dLon);
         }
      }
      float MV = getMissingValue(var); // The output file's missing value indicator
      for(int t = 0; t < mNTime; t++) {
         float offset = getOffset(var);
         float scale = getScale(var);
         FieldPtr field = getField(varType, t);
         if(field != NULL) { // TODO: Can't be null if coming from reference
            float* values = new float[mNLat*mNLon];

            int index = 0;
            for(int lat = 0; lat < mNLat; lat++) {
               for(int lon = 0; lon < mNLon; lon++) {
                  float value = (*field)(lat,lon,0);
                  if(!Util::isValid(value)) {
                     // Field has missing value indicator and the value is missing
                     // Save values using the file's missing indicator value
                     value = MV;
                  }
                  else {
                     value = ((*field)(lat,lon,0) - offset)/scale;
                  }
                  values[index] = value;
                  index++;
               }
            }
            int numDims = var->num_dims();
            if(numDims == 4) {
               var->set_cur(t, 0, 0, 0);
               var->put(values, 1, 1, mNLat, mNLon);
            }
            else if(numDims == 3) {
               var->set_cur(t, 0, 0);
               var->put(values, 1, mNLat, mNLon);
            }
            else {
               std::stringstream ss;
               ss << "Cannot write variable '" << variable << "' from '" << getFilename() << "'";
               Util::error(ss.str());
            }
            setAttribute(var, "coordinates", "longitude latitude");
            setAttribute(var, "units", Variable::getUnits(varType));
            setAttribute(var, "standard_name", Variable::getStandardName(varType));
            delete[] values;
         }
      }
      setMissingValue(var, MV);
   }
}