Skip to content

Commit cceae63

Browse files
Implemented multiplication operator
1 parent f5e44d1 commit cceae63

File tree

4 files changed

+18
-2
lines changed

4 files changed

+18
-2
lines changed

include/fields/field_definition.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ class FieldDefinition {
126126
* @brief Initializes a field instance based on this definition
127127
* @param field The field to initialize
128128
*/
129-
void initializeField(Field* field);
129+
virtual void initializeField(Field* field);
130130

131131
/**
132132
* @brief Adds an input field link

include/fields/multiplication.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ class Multiplication : public AbstractFunctionDefinition {
1111
// Constructor
1212
Multiplication(Type* ref, const std::string& name);
1313

14+
void initializeField(Field* field) override;
15+
1416
// Overridden method from AbstractFunctionDefinition
1517
double computeUpdate(Obj* obj, FieldLinkDefinition* fl, double u) override;
1618
};

src/fields/multiplication.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@
44
Multiplication::Multiplication(Type* ref, const std::string& name)
55
: AbstractFunctionDefinition(ref, name, 2, 0.0) {}
66

7+
void Multiplication::initializeField(Field* field) {
8+
Obj* toObj = field->getObject();
9+
FieldDefinition* fieldDef = field->getFieldDefinition();
10+
std::vector<FieldLinkDefinition*> inputs = fieldDef->getInputs();
11+
double valueArg0 = inputs[0]->getInputValue(toObj);
12+
double valueArg1 = inputs[1]->getInputValue(toObj);
13+
14+
field->setValue(valueArg0 * valueArg1);
15+
}
16+
717
// Overridden computeUpdate method
818
double Multiplication::computeUpdate(Obj* obj, FieldLinkDefinition* fl, double u) {
919
return u * getInputs()[fl->getArgument() == 0 ? 1 : 0]->getInputValue(obj);

src/fields/test_object.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ Obj* TestObject::followSingleRelation(const Relation* rel) {
88
if (rel == &TestType::TEST_RELATION_FROM || rel == &TestType::TEST_RELATION_TO) {
99
return getRelatedTestObject();
1010
} else {
11-
throw std::runtime_error("Invalid Relation");
11+
if(rel != nullptr) {
12+
throw std::runtime_error("Object:" + this->toString() + " Invalid Relation:" + std::to_string(rel->getRelationId()) + ":" + rel->getRelationLabel());
13+
} else {
14+
throw std::runtime_error("Object:" + this->toString() + " Invalid Relation: nullptr");
15+
}
1216
}
1317
}
1418

0 commit comments

Comments
 (0)