mirror of
https://github.com/Ardour/ardour.git
synced 2025-12-12 01:26:31 +01:00
Canvas: reindent Kiwi code, and provide operator<<(ostream&) for several objects
This commit is contained in:
parent
ba3515e619
commit
1baa8d68c7
4 changed files with 165 additions and 109 deletions
|
|
@ -6,6 +6,7 @@
|
||||||
| The full license is in the file LICENSE, distributed with this software.
|
| The full license is in the file LICENSE, distributed with this software.
|
||||||
|----------------------------------------------------------------------------*/
|
|----------------------------------------------------------------------------*/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
#include <ostream>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "expression.h"
|
#include "expression.h"
|
||||||
|
|
@ -24,6 +25,22 @@ enum RelationalOperator
|
||||||
OP_EQ
|
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
|
class Constraint
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
@ -58,6 +75,13 @@ public:
|
||||||
return !m_data;
|
return !m_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool involves (Variable const & v) const {
|
||||||
|
if (expression().involves (v)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static Expression reduce(const Expression &expr)
|
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
|
} // namespace kiwi
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
| The full license is in the file LICENSE, distributed with this software.
|
| The full license is in the file LICENSE, distributed with this software.
|
||||||
|----------------------------------------------------------------------------*/
|
|----------------------------------------------------------------------------*/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
#include <ostream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "term.h"
|
#include "term.h"
|
||||||
|
|
||||||
|
|
@ -44,9 +45,28 @@ public:
|
||||||
return result;
|
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:
|
private:
|
||||||
std::vector<Term> m_terms;
|
std::vector<Term> m_terms;
|
||||||
double m_constant;
|
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
|
} // namespace kiwi
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
| The full license is in the file LICENSE, distributed with this software.
|
| The full license is in the file LICENSE, distributed with this software.
|
||||||
|----------------------------------------------------------------------------*/
|
|----------------------------------------------------------------------------*/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
#include <ostream>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include "variable.h"
|
#include "variable.h"
|
||||||
|
|
||||||
|
|
@ -48,4 +49,10 @@ private:
|
||||||
double m_coefficient;
|
double m_coefficient;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static std::ostream& operator<< (std::ostream& o, kiwi::Term const & t)
|
||||||
|
{
|
||||||
|
return o << t.variable().name() << " * " << t.coefficient();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace kiwi
|
} // namespace kiwi
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
// operator== is used for symbolics
|
// operator== is used for symbolics
|
||||||
bool equals(const Variable &other)
|
bool equals(const Variable &other) const
|
||||||
{
|
{
|
||||||
return m_data == other.m_data;
|
return m_data == other.m_data;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue