Beispiel #1
0
 const Data& operator[](const String& key) const {
     if (isHash()) {
         const auto it = hash_.find(key);
         if (it == hash_.end()) {
             return kNilData;
         }
         return it->second;
     } else if (isDrop()) {
         return (*drop_)[key];
     } else {
         throw std::runtime_error("[] requires a hash or drop");
     }
 }
Beispiel #2
0
bool HashFile::readFromFile(const QString &fileName)
{
    QFile f(!fileName.isEmpty() ? fileName : m_fullName + fileNameExtension());
    if (!f.open(QIODevice::ReadOnly))
        return false;
    const QList<QByteArray> parts = f.readLine().trimmed().split(' ');
    if (parts.size() != 3)
    {
        qCritical() << "invalid hash file format" << f.fileName();
        return false;
    }
    if (!isHash(parts[0]))
        return false;

    m_hash = parts[0];
    return true;
}
Beispiel #3
0
 bool containsKey(const String& key) const {
     if (!isHash()) {
         throw std::runtime_error("containsKey requires a hash");
     }
     return hash_.find(key) != hash_.end();
 }
Beispiel #4
0
 void insert(const String& key, const Data& value) {
     if (!isHash()) {
         throw std::runtime_error("insert() requires a hash");
     }
     hash_[key] = value;
 }
Beispiel #5
0
 Hash& hash() {
     if (!isHash()) {
         throw std::runtime_error("hash() requires an array");
     }
     return hash_;
 }