formalized valuehint as a class

This commit is contained in:
itsmattkc
2021-09-21 20:13:14 -07:00
parent 677277c16d
commit dc7f7a6dda
8 changed files with 62 additions and 31 deletions
+1 -1
View File
@@ -51,7 +51,7 @@ ClipBlock::ClipBlock() :
IgnoreHashingFrom(kReverseInput);
PrependInput(kBufferIn, NodeValue::kNone, InputFlags(kInputFlagNotKeyframable));
SetValueHintForInput(kBufferIn, {NodeValue::kBuffer, -1, QString()});
SetValueHintForInput(kBufferIn, ValueHint(NodeValue::kBuffer));
}
Node *ClipBlock::copy() const
+11 -16
View File
@@ -1015,12 +1015,7 @@ int Node::InputArraySize(const QString &id) const
void Node::Hash(const Node *node, const ValueHint &hint, QCryptographicHash &hash, const NodeGlobals &globals, const VideoParams &video_params)
{
if (!hint.type.isEmpty()) {
hash.addData(reinterpret_cast<const char*>(hint.type.constData()), sizeof(NodeValue::Type) * hint.type.size());
}
hash.addData(reinterpret_cast<const char*>(&hint.index), sizeof(hint.index));
hash.addData(hint.tag.toUtf8());
hint.Hash(hash);
node->Hash(hash, globals, video_params);
}
@@ -2468,11 +2463,11 @@ void NodeRemovePositionFromAllContextsCommand::undo()
void Node::ValueHint::Hash(QCryptographicHash &hash) const
{
// Add value hint
foreach (NodeValue::Type t, type) {
hash.addData(reinterpret_cast<const char*>(&t), sizeof(t));
if (!types().isEmpty()) {
hash.addData(reinterpret_cast<const char*>(types().constData()), sizeof(NodeValue::Type) * types().size());
}
hash.addData(reinterpret_cast<const char *>(&index), sizeof(index));
hash.addData(tag.toUtf8());
hash.addData(reinterpret_cast<const char*>(&index()), sizeof(index()));
hash.addData(tag().toUtf8());
}
void Node::ValueHint::Load(QXmlStreamReader *reader)
@@ -2481,15 +2476,15 @@ void Node::ValueHint::Load(QXmlStreamReader *reader)
if (reader->name() == QStringLiteral("types")) {
while (XMLReadNextStartElement(reader)) {
if (reader->name() == QStringLiteral("type")) {
type.append(static_cast<NodeValue::Type>(reader->readElementText().toInt()));
type_.append(static_cast<NodeValue::Type>(reader->readElementText().toInt()));
} else {
reader->skipCurrentElement();
}
}
} else if (reader->name() == QStringLiteral("index")) {
index = reader->readElementText().toInt();
index_ = reader->readElementText().toInt();
} else if (reader->name() == QStringLiteral("tag")) {
tag = reader->readElementText();
tag_ = reader->readElementText();
} else {
reader->skipCurrentElement();
}
@@ -2500,15 +2495,15 @@ void Node::ValueHint::Save(QXmlStreamWriter *writer) const
{
writer->writeStartElement(QStringLiteral("types"));
for (auto it=type.cbegin(); it!=type.cend(); it++) {
for (auto it=type_.cbegin(); it!=type_.cend(); it++) {
writer->writeTextElement(QStringLiteral("type"), QString::number(*it));
}
writer->writeEndElement(); // types
writer->writeTextElement(QStringLiteral("index"), QString::number(index));
writer->writeTextElement(QStringLiteral("index"), QString::number(index_));
writer->writeTextElement(QStringLiteral("tag"), tag);
writer->writeTextElement(QStringLiteral("tag"), tag_);
}
}
+40 -4
View File
@@ -462,15 +462,51 @@ public:
int InputArraySize(const QString& id) const;
struct ValueHint {
QVector<NodeValue::Type> type;
int index = -1;
QString tag;
class ValueHint {
public:
explicit ValueHint(const QVector<NodeValue::Type> &types = QVector<NodeValue::Type>(), int index = -1, const QString &tag = QString()) :
type_(types),
index_(index),
tag_(tag)
{
}
explicit ValueHint(const QVector<NodeValue::Type> &types, const QString &tag) :
type_(types),
index_(-1),
tag_(tag)
{
}
explicit ValueHint(int index) :
index_(index)
{
}
explicit ValueHint(const QString &tag) :
index_(-1),
tag_(tag)
{
}
void Hash(QCryptographicHash &hash) const;
void Load(QXmlStreamReader *reader);
void Save(QXmlStreamWriter *writer) const;
const QVector<NodeValue::Type> &types() const { return type_; }
const int &index() const { return index_; }
const QString& tag() const { return tag_; }
void set_type(const QVector<NodeValue::Type> &type) { type_ = type; }
void set_index(const int &index) { index_ = index; }
void set_tag(const QString &tag) { tag_ = tag; }
private:
QVector<NodeValue::Type> type_;
int index_;
QString tag_;
};
static void Hash(const Node *node, const ValueHint &hint, QCryptographicHash& hash, const NodeGlobals &globals, const VideoParams& video_params);
+4 -4
View File
@@ -106,18 +106,18 @@ NodeValue NodeTraverser::GenerateRowValueElement(const Node::ValueHint &hint, No
int NodeTraverser::GenerateRowValueElementIndex(const Node::ValueHint &hint, NodeValue::Type preferred_type, const NodeValueTable *table)
{
QVector<NodeValue::Type> types = hint.type;
QVector<NodeValue::Type> types = hint.types();
if (types.isEmpty()) {
types.append(preferred_type);
}
if (hint.index == -1) {
if (hint.index() == -1) {
// Get most recent value with this type and tag
return table->GetValueIndex(types, hint.tag);
return table->GetValueIndex(types, hint.tag());
} else {
// Try to find value at this index
int index = table->Count() - 1 - hint.index;
int index = table->Count() - 1 - hint.index();
int diff = 0;
while (index + diff < table->Count() && index - diff >= 0) {