/[ascend]/trunk/pygtk/relation.cpp
ViewVC logotype

Contents of /trunk/pygtk/relation.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 736 - (show annotations) (download) (as text)
Wed Jul 5 04:56:26 2006 UTC (18 years, 9 months ago) by johnpye
File MIME type: text/x-c++src
File size: 1562 byte(s)
Relation expressions shown in diagnose window
(click in incidence matrix, then (i) or alt-r)
1 #include <iostream>
2 #include <stdexcept>
3 using namespace std;
4
5 #include "relation.h"
6 #include "simulation.h"
7 #include "variable.h"
8
9 extern "C"{
10 #include <utilities/ascConfig.h>
11 #include <utilities/ascMalloc.h>
12
13 #include <general/dstring.h>
14 #include <compiler/compiler.h>
15 #include <compiler/symtab.h>
16 #include <compiler/instance_enum.h>
17 #include <compiler/instance_io.h>
18 }
19
20
21 Relation::Relation(){
22 sim=NULL;
23 rel=NULL;
24 }
25
26 Relation::Relation(const Relation &old) : sim(old.sim), rel(old.rel){
27 // copy ctor
28 }
29
30 Relation::Relation(Simulation *sim, struct rel_relation *rel) : sim(sim), rel(rel){
31 if(rel==NULL)throw runtime_error("Relation::Relation: rel is NULL");
32 }
33
34 const string
35 Relation::getName() const{
36 char *n = WriteInstanceNameString((struct Instance *)rel_instance(rel),sim->getModel().getInternalType());
37 string name = n;
38 ascfree(n);
39
40 return name;
41 }
42
43 const double
44 Relation::getResidual() const{
45 return rel_residual(rel);
46 }
47
48 const std::vector<Variable>
49 Relation::getIncidentVariables() const{
50 struct var_variable **incid = rel_incidence_list_to_modify(rel);
51 int n = rel_n_incidences(rel);
52 vector<Variable> v;
53 for(int i=0; i<n; ++i){
54 v.push_back(Variable(sim,incid[i]));
55 }
56 return v;
57 }
58
59 const int
60 Relation::getNumIncidentVariables() const{
61 return rel_n_incidences(rel);
62 }
63
64 Instanc
65 Relation::getInstance() const{
66 return Instanc((struct Instance *)rel_instance(rel));
67 }
68
69 string
70 Relation::getRelationAsString() const{
71 if(sim==NULL){
72 throw runtime_error("Simulation not set");
73 }
74 return getInstance().getRelationAsString(sim->getModel());
75 }
76

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22