-
Notifications
You must be signed in to change notification settings - Fork 0
/
cysw_support.cc
67 lines (56 loc) · 1.93 KB
/
cysw_support.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Support functions for cysw.
#include <sstream>
#include "cysw_support.h"
#include "cassowary/LinearEquation.h"
#include "cassowary/LinearInequality.h"
#include "cassowary/Errors.h"
size_t get_P_Constraint_addr(P_Constraint *pcn) {
return reinterpret_cast<size_t>(pcn->ptr());
}
std::vector<size_t> get_cpp_exception_constraint_pointers() {
std::vector<size_t> constraint_pointers;
try {
// Re-throw the exception.
throw;
}
catch (const ExCLError &exn) {
const ConstraintSet* cset = exn.explanation();
if (cset != NULL) {
ConstraintSet::const_iterator it = cset->begin();
for (; it != cset->end(); ++it) {
constraint_pointers.push_back(reinterpret_cast<size_t>((*it).ptr()));
}
}
}
return constraint_pointers;
}
std::string get_cpp_exception_message() {
std::string message;
try {
// Re-throw the exception.
throw;
}
catch (const ExCLError &exn) {
message = exn.description();
}
return message;
}
std::string solver_str(SimplexSolver *solver) {
std::ostringstream ss;
solver->PrintOn(ss);
return ss.str();
}
P_Constraint *newLinearEquation(const P_LinearExpression &lhs, const P_LinearExpression &rhs, const Strength &strength, double weight) {
P_Constraint result(new LinearEquation(lhs, rhs, strength, weight));
return new P_Constraint(static_cast< const P_Constraint& >(result));
}
P_Constraint *newLinearInequality(const P_LinearExpression &lhs, CnRelation op, const P_LinearExpression &rhs, const Strength &strength, double weight) {
P_Constraint result(new LinearInequality(lhs, op, rhs, strength, weight));
return new P_Constraint(static_cast< const P_Constraint& >(result));
}
P_LinearExpression newLinearExpression(double constant) {
return P_LinearExpression(new LinearExpression(constant));
}
void delete_P_Constraint(P_Constraint *pcn) {
delete pcn;
}