Skip to content

Commit 5637171

Browse files
jmirabelolivier-stasse
authored andcommitted
Add boolean operations.
1 parent e91021f commit 5637171

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

src/matrix/operator.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,6 +1076,50 @@ namespace dynamicgraph {
10761076
REGISTER_VARIADIC_OP(Multiplier<VectorQuaternion >,Multiply_of_quaternion);
10771077
REGISTER_VARIADIC_OP(Multiplier<double >,Multiply_of_double);
10781078

1079+
/* --- BOOLEAN --------------------------------------------------------- */
1080+
template <int operation>
1081+
struct BoolOp
1082+
: public VariadicOpHeader<bool,bool>
1083+
{
1084+
typedef VariadicOp<BoolOp> Base;
1085+
1086+
void operator()( const std::vector<const bool*>& vs, bool& res ) const
1087+
{
1088+
// TODO computation could be optimized with lazy evaluation of the
1089+
// signals. When the output result is know, the remaining signals are
1090+
// not computed.
1091+
assert (vs.size() == coeffs.size());
1092+
if (vs.size() == 0) return;
1093+
res = *vs[0];
1094+
for (std::size_t i = 1; i < vs.size(); ++i)
1095+
switch (operation) {
1096+
case 0:
1097+
if (!res) return;
1098+
res = *vs[i];
1099+
break;
1100+
case 1:
1101+
if (res) return;
1102+
res = *vs[i];
1103+
break;
1104+
}
1105+
}
1106+
1107+
void initialize(Base* ent,
1108+
Entity::CommandMap_t& commandMap )
1109+
{
1110+
using namespace dynamicgraph::command;
1111+
1112+
ADD_COMMAND( "setSignalNumber", makeCommandVoid1(*(typename Base::Base*)ent, &Base::setSignalNumber,
1113+
docCommandVoid1("set the number of input boolean.", "int (size)")));
1114+
1115+
commandMap.insert(std::make_pair( "getSignalNumber",
1116+
new Getter<Base, int> (*ent, &Base::getSignalNumber,
1117+
"Get the number of input bool.")));
1118+
}
1119+
};
1120+
REGISTER_VARIADIC_OP(BoolOp<0>,And);
1121+
REGISTER_VARIADIC_OP(BoolOp<1>,Or);
1122+
10791123
}
10801124
}
10811125

0 commit comments

Comments
 (0)