SeExpr

EditableExpression.h
Go to the documentation of this file.
1 /*
2 * Copyright Disney Enterprises, Inc. All rights reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License
6 * and the following modification to it: Section 6 Trademarks.
7 * deleted and replaced with:
8 *
9 * 6. Trademarks. This License does not grant permission to use the
10 * trade names, trademarks, service marks, or product names of the
11 * Licensor and its affiliates, except as required for reproducing
12 * the content of the NOTICE file.
13 *
14 * You may obtain a copy of the License at
15 * http://www.apache.org/licenses/LICENSE-2.0
16 *
17 * @file EditableExpression.h
18 * @author Andrew Selle
19 */
20 #ifndef __EditableExpression__
21 #define __EditableExpression__
22
23 #include <vector>
24 #include <string>
25
26 class Editable;
27
29 class EditableExpression {
30 std::string _expr; // original full expression
31 typedef std::vector<Editable*> Editables;
32 std::vector<Editable*> _editables; // control that can edit the expression
33 std::vector<std::string> _variables;
34
35 public:
36 EditableExpression();
37 ~EditableExpression();
38
40 void setExpr(const std::string& expr);
41
43 std::string getEditedExpr() const;
44
46 bool controlsMatch(const EditableExpression& other) const;
47
49 void updateString(const EditableExpression& other);
50
52 Editable* operator[](const int i) { return _editables[i]; }
53
55 size_t size() const { return _editables.size(); }
56
58 const std::vector<std::string>& getVariables() const { return _variables; }
59
60 private:
62 void cleanup();
63 };
64
65 #endif
EditableExpression::setExpr
void setExpr(const std::string &expr)
Set's expressions and parses it into "control editable form".
Definition: EditableExpression.cpp:30
Editable
Definition: Editable.h:40
EditableExpression
Factors a SeExpr into an editable expression with controls (i.e. value boxes, curve boxes)
Definition: EditableExpression.h:29
EditableExpression::operator[]
Editable * operator[](const int i)
Access an editable parameter.
Definition: EditableExpression.h:52
EditableExpression::Editables
std::vector< Editable * > Editables
Definition: EditableExpression.h:31
EditableExpression::~EditableExpression
~EditableExpression()
Definition: EditableExpression.cpp:28
EditableExpression::cleanup
void cleanup()
clean memeory
Definition: EditableExpression.cpp:63
EditableExpression::size
size_t size() const
Return the count of editable parameters.
Definition: EditableExpression.h:55
EditableExpression::EditableExpression
EditableExpression()
Definition: EditableExpression.cpp:26
EditableExpression::controlsMatch
bool controlsMatch(const EditableExpression &other) const
Check if the other editable expression has editables that all match i.e. the controls are same.
Definition: EditableExpression.cpp:95
EditableExpression::getVariables
const std::vector< std::string > & getVariables() const
Get list of commentsø
Definition: EditableExpression.h:58
EditableExpression::updateString
void updateString(const EditableExpression &other)
Update the string refered to into the controls (this is only valid if controlsmatch)
Definition: EditableExpression.cpp:82
EditableExpression::getEditedExpr
std::string getEditedExpr() const
Return a reconstructed expression using all the editable's current values.
Definition: EditableExpression.cpp:69
EditableExpression::_variables
std::vector< std::string > _variables
Definition: EditableExpression.h:33
EditableExpression::_expr
std::string _expr
Definition: EditableExpression.h:30
EditableExpression::_editables
std::vector< Editable * > _editables
Definition: EditableExpression.h:32
expr
</pre >< h3 > Binding our variable reference</h3 > If we now tried to use the variable would still not be found by our expressions To make it bindable we need to override the resolveVar() function as follows</pre >< h3 > Variable setting</h3 > Next we need to make a way of setting the variable As the controlling code will use the expression it will repeatedly alternate between setting the independent variables that are used and calling evaluate(). What it has to do depends very much on the application. In this case we only need to set the independent variable x as</pre >< h2 > Evaluating expressions</h2 > Evaluating an expression is pretty easy But before we can do that we need to make an instance< pre > GrapherExpr expr("x+x^2")