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"); } }
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; }
bool containsKey(const String& key) const { if (!isHash()) { throw std::runtime_error("containsKey requires a hash"); } return hash_.find(key) != hash_.end(); }
void insert(const String& key, const Data& value) { if (!isHash()) { throw std::runtime_error("insert() requires a hash"); } hash_[key] = value; }
Hash& hash() { if (!isHash()) { throw std::runtime_error("hash() requires an array"); } return hash_; }