Canvas: reindent Kiwi code, and provide operator<<(ostream&) for several objects
This commit is contained in:
parent
ba3515e619
commit
1baa8d68c7
|
@ -6,6 +6,7 @@
|
|||
| The full license is in the file LICENSE, distributed with this software.
|
||||
|----------------------------------------------------------------------------*/
|
||||
#pragma once
|
||||
#include <ostream>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include "expression.h"
|
||||
|
@ -24,6 +25,22 @@ enum RelationalOperator
|
|||
OP_EQ
|
||||
};
|
||||
|
||||
static std::ostream& operator<< (std::ostream& o, RelationalOperator op)
|
||||
{
|
||||
switch (op) {
|
||||
case OP_LE:
|
||||
o << "<=";
|
||||
break;
|
||||
case OP_GE:
|
||||
o << ">=";
|
||||
break;
|
||||
case OP_EQ:
|
||||
o << "==";
|
||||
break;
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
class Constraint
|
||||
{
|
||||
|
||||
|
@ -58,6 +75,13 @@ public:
|
|||
return !m_data;
|
||||
}
|
||||
|
||||
bool involves (Variable const & v) const {
|
||||
if (expression().involves (v)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private:
|
||||
static Expression reduce(const Expression &expr)
|
||||
{
|
||||
|
@ -116,4 +140,9 @@ private:
|
|||
}
|
||||
};
|
||||
|
||||
static std::ostream& operator<< (std::ostream& o, kiwi::Constraint const & c)
|
||||
{
|
||||
return o << c.expression() << " OP " << c.op();
|
||||
}
|
||||
|
||||
} // namespace kiwi
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
| The full license is in the file LICENSE, distributed with this software.
|
||||
|----------------------------------------------------------------------------*/
|
||||
#pragma once
|
||||
#include <ostream>
|
||||
#include <vector>
|
||||
#include "term.h"
|
||||
|
||||
|
@ -44,9 +45,28 @@ public:
|
|||
return result;
|
||||
}
|
||||
|
||||
bool involves (Variable const & v) const {
|
||||
for (std::vector<Term>::const_iterator it = m_terms.begin(); it != m_terms.end(); ++it) {
|
||||
if (it->variable().equals (v)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<Term> m_terms;
|
||||
double m_constant;
|
||||
};
|
||||
|
||||
static std::ostream& operator<<(std::ostream& o, kiwi::Expression const &e)
|
||||
{
|
||||
o << e.constant() << " + ";
|
||||
for (std::vector<kiwi::Term>::const_iterator it = e.terms().begin(); it != e.terms().end(); ++it) {
|
||||
o << (*it) << ' ';
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
} // namespace kiwi
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
| The full license is in the file LICENSE, distributed with this software.
|
||||
|----------------------------------------------------------------------------*/
|
||||
#pragma once
|
||||
#include <ostream>
|
||||
#include <utility>
|
||||
#include "variable.h"
|
||||
|
||||
|
@ -48,4 +49,10 @@ private:
|
|||
double m_coefficient;
|
||||
};
|
||||
|
||||
static std::ostream& operator<< (std::ostream& o, kiwi::Term const & t)
|
||||
{
|
||||
return o << t.variable().name() << " * " << t.coefficient();
|
||||
}
|
||||
|
||||
} // namespace kiwi
|
||||
|
||||
|
|
|
@ -68,7 +68,7 @@ public:
|
|||
}
|
||||
|
||||
// operator== is used for symbolics
|
||||
bool equals(const Variable &other)
|
||||
bool equals(const Variable &other) const
|
||||
{
|
||||
return m_data == other.m_data;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user