Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
tsoc
openmm
Commits
c0ad3f03
Commit
c0ad3f03
authored
Nov 20, 2009
by
Peter Eastman
Browse files
Improved display of expressions when printing them to a stream
parent
055e308a
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
8 deletions
+34
-8
libraries/lepton/include/lepton/Operation.h
libraries/lepton/include/lepton/Operation.h
+21
-0
libraries/lepton/src/ParsedExpression.cpp
libraries/lepton/src/ParsedExpression.cpp
+13
-8
No files found.
libraries/lepton/include/lepton/Operation.h
View file @
c0ad3f03
...
...
@@ -96,6 +96,12 @@ public:
* @param variable the variable with respect to which the derivate should be taken
*/
virtual
ExpressionTreeNode
differentiate
(
const
std
::
vector
<
ExpressionTreeNode
>&
children
,
const
std
::
vector
<
ExpressionTreeNode
>&
childDerivs
,
const
std
::
string
&
variable
)
const
=
0
;
/**
* Get whether this operation should be displayed with infix notation.
*/
virtual
bool
isInfixOperator
()
const
{
return
false
;
}
virtual
bool
operator
!=
(
const
Operation
&
op
)
const
{
return
op
.
getId
()
!=
getId
();
}
...
...
@@ -264,6 +270,9 @@ public:
return
args
[
0
]
+
args
[
1
];
}
ExpressionTreeNode
differentiate
(
const
std
::
vector
<
ExpressionTreeNode
>&
children
,
const
std
::
vector
<
ExpressionTreeNode
>&
childDerivs
,
const
std
::
string
&
variable
)
const
;
bool
isInfixOperator
()
const
{
return
true
;
}
};
class
Operation
::
Subtract
:
public
Operation
{
...
...
@@ -286,6 +295,9 @@ public:
return
args
[
0
]
-
args
[
1
];
}
ExpressionTreeNode
differentiate
(
const
std
::
vector
<
ExpressionTreeNode
>&
children
,
const
std
::
vector
<
ExpressionTreeNode
>&
childDerivs
,
const
std
::
string
&
variable
)
const
;
bool
isInfixOperator
()
const
{
return
true
;
}
};
class
Operation
::
Multiply
:
public
Operation
{
...
...
@@ -308,6 +320,9 @@ public:
return
args
[
0
]
*
args
[
1
];
}
ExpressionTreeNode
differentiate
(
const
std
::
vector
<
ExpressionTreeNode
>&
children
,
const
std
::
vector
<
ExpressionTreeNode
>&
childDerivs
,
const
std
::
string
&
variable
)
const
;
bool
isInfixOperator
()
const
{
return
true
;
}
};
class
Operation
::
Divide
:
public
Operation
{
...
...
@@ -330,6 +345,9 @@ public:
return
args
[
0
]
/
args
[
1
];
}
ExpressionTreeNode
differentiate
(
const
std
::
vector
<
ExpressionTreeNode
>&
children
,
const
std
::
vector
<
ExpressionTreeNode
>&
childDerivs
,
const
std
::
string
&
variable
)
const
;
bool
isInfixOperator
()
const
{
return
true
;
}
};
class
Operation
::
Power
:
public
Operation
{
...
...
@@ -352,6 +370,9 @@ public:
return
std
::
pow
(
args
[
0
],
args
[
1
]);
}
ExpressionTreeNode
differentiate
(
const
std
::
vector
<
ExpressionTreeNode
>&
children
,
const
std
::
vector
<
ExpressionTreeNode
>&
childDerivs
,
const
std
::
string
&
variable
)
const
;
bool
isInfixOperator
()
const
{
return
true
;
}
};
class
Operation
::
Negate
:
public
Operation
{
...
...
libraries/lepton/src/ParsedExpression.cpp
View file @
c0ad3f03
...
...
@@ -239,6 +239,10 @@ ExpressionProgram ParsedExpression::createProgram() const {
}
ostream
&
Lepton
::
operator
<<
(
ostream
&
out
,
const
ExpressionTreeNode
&
node
)
{
if
(
node
.
getOperation
().
isInfixOperator
()
&&
node
.
getChildren
().
size
()
==
2
)
{
out
<<
"("
<<
node
.
getChildren
()[
0
]
<<
")"
<<
node
.
getOperation
().
getName
()
<<
"("
<<
node
.
getChildren
()[
1
]
<<
")"
;
}
else
{
out
<<
node
.
getOperation
().
getName
();
if
(
node
.
getChildren
().
size
()
>
0
)
{
out
<<
"("
;
...
...
@@ -249,6 +253,7 @@ ostream& Lepton::operator<<(ostream& out, const ExpressionTreeNode& node) {
}
out
<<
")"
;
}
}
return
out
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment