Created
March 12, 2019 09:47
-
-
Save TheZoq2/3beceade58d104aa8bdeb80b01f19516 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template<class T> | |
class If : public T { | |
public: | |
static Rc<If> create( | |
Rc<BoolNode> condition, | |
Rc<T> on_true, | |
Rc<T> on_false | |
) { | |
return std::shared_ptr<If>(new If(condition, on_true, on_false)); | |
} | |
std::string variable_name() const override { | |
return "if_" + condition->variable_name() + "_" + | |
on_true->variable_name() + "_" + on_false->variable_name(); | |
} | |
std::vector<std::string> get_code() override { | |
return {}; | |
} | |
std::vector<Rc<Node>> get_children() const override { | |
return {}; | |
} | |
protected: | |
Rc<BoolNode> condition; | |
Rc<T> on_true; | |
Rc<T> on_false; | |
If(Rc<BoolNode> condition, Rc<T> on_true, Rc<T> on_false) | |
: condition(condition), on_true(on_true), on_false(on_false) | |
{ | |
static_assert(std::is_base_of<Node, T>::value, "If-result must be a node"); | |
} | |
}; | |
class IfFractional : public If<FracNode> { | |
public: | |
static Rc<IfFractional> create( | |
Rc<BoolNode> condition, | |
Rc<FracNode> on_true, | |
Rc<FracNode> on_false | |
) { | |
return std::shared_ptr<IfFractional>(new IfFractional(condition, on_true, on_false)); | |
} | |
// TODO: Test | |
double min() const override { | |
return 0; | |
} | |
// TODO: Test | |
double max() const override { | |
return 0; | |
} | |
ExecutionType calculate_value() override { | |
return 0; | |
} | |
private: | |
IfFractional( | |
Rc<BoolNode> condition, | |
Rc<FracNode> on_true, | |
Rc<FracNode> on_false | |
) | |
: If<FracNode>(condition, on_true, on_false) | |
{} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment