/[ascend]/trunk/ascxx/annotation.cpp
ViewVC logotype

Contents of /trunk/ascxx/annotation.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2327 - (show annotations) (download) (as text)
Wed Dec 22 07:17:24 2010 UTC (8 years, 11 months ago) by jpye
File MIME type: text/x-c++src
File size: 4294 byte(s)
Merging in refactor of the C++ code, which is moved out of 'pygtk' and into 'ascxx'.
Adding support for IPOPT 3.9.1, the current latest version.
Support in dtar for parallel builds (possibly needs some testing still).
1 #include "annotation.h"
2
3 extern "C"{
4 #include <ascend/compiler/notate.h>
5 #include <ascend/compiler/notequery.h>
6 #include <ascend/utilities/error.h>
7 #include <ascend/general/panic.h>
8 }
9
10 #include <stdexcept>
11 #include <iostream>
12
13 using namespace std;
14
15 AnnotationDatabase::AnnotationDatabase(const SymChar &dbid){
16 this->dbid = dbid.getInternalType();
17 }
18
19 /**
20 This is a C++ wrapper for the GetNotes function from notate.h.
21 It doesn't allow access to the full range of functionality from GetNotes
22 though.
23 */
24 vector<Annotation>
25 AnnotationDatabase::getNotes(const Type &type, const SymChar *lang
26 , const SymChar *id, const SymChar *method, const int datatypeint
27 ){
28 struct gl_list_t *res;
29 if(datatypeint < (int)nd_wild && datatypeint > (int)nd_anonymous){
30 throw runtime_error("Invalid datatype flag");
31 }
32
33 symchar *lang1, *id1, *method1;
34
35 if(lang==NULL)lang1 = NOTESWILD;
36 else lang1 = lang->getInternalType();
37
38 if(id==NULL)id1 = NOTESWILD;
39 else id1 = id->getInternalType();
40
41 if(method==NULL)method1 = NOTESWILD;
42 else method1 = method->getInternalType();
43
44 res = GetNotes(dbid, type.getName().getInternalType(), lang1, id1, method1, (enum NoteData)datatypeint);
45
46 if(res==NULL){
47 throw runtime_error("NULL from GetNotes");
48 }
49
50 vector<Annotation> v;
51 for(unsigned i=1; i<=gl_length(res); ++i){
52 v.push_back(Annotation((struct Note *)gl_fetch(res,i)));
53 }
54
55 gl_destroy(res);
56
57 return v;
58 }
59
60 /**
61 Return the note corresponding to a variable within a type. This function
62 is cogniscent of the type hierarchy; it will locate the note on this
63 variable in the most refined parent type of 'type' for which it is present.
64 This makes it possible to define a note in a base-type and then access it
65 from a more refined type.
66 */
67 const char *
68 AnnotationDatabase::getNoteForVariable(const Type &type
69 , const SymChar *varname
70 , const SymChar *lang
71 ){
72 return notes_get_for_variable(this->dbid, type.getInternalType(), varname->getInternalType(), lang->getInternalType());
73 }
74
75 /**
76 Return most-refined note corresponding all variables within a type. Only
77 notes having 'language' lang are returned.
78 */
79 vector<Annotation>
80 AnnotationDatabase::getTypeRefinedNotesLang(const Type &type
81 , const SymChar *lang
82 ){
83 struct gl_list_t *l = notes_refined_for_type_with_lang(
84 this->dbid
85 , type.getInternalType()
86 , lang->getInternalType()
87 );
88
89 vector<Annotation> v;
90 if(l != NULL){
91 for(unsigned i=1; i<=gl_length(l); ++i){
92 v.push_back(Annotation((struct Note *)gl_fetch(l,i)));
93 }
94 }
95 return v;
96 }
97
98
99 Annotation::Annotation(){
100 n = NULL;
101 cerr << "Created Annotation with NULL Note" << endl;
102 }
103
104 Annotation::~Annotation(){
105 // do nothing
106 }
107
108 Annotation::Annotation(struct Note *n){
109 this->n = n;
110 }
111
112 const char *
113 Annotation::getId() const{
114 symchar *m = GetNoteId(n);
115 if(m==NULL){
116 return NULL;
117 }
118 return SCP(m);
119 }
120
121 /**
122 @return the name of the method to which this note was assigned, or NULL if the note was not assigned to a method.
123 */
124 const char *
125 Annotation::getMethod() const{
126 symchar *m = GetNoteMethod(n);
127 if(m==NULL){
128 return NULL;
129 }
130 return SCP(m);
131 }
132
133 /**
134 @return the name of the type to which this note is assigned
135 */
136 const SymChar
137 Annotation::getType() const{
138 asc_assert(GetNoteType(n)!=NULL);
139 return SymChar(SCP(GetNoteType(n)));
140 }
141
142 /**
143 Get the 'language' of a note. This roughly corresponds to the *purpose*
144 that the note exists for: informing the end-user, providing parameters to
145 the solver, giving additional data such as icons for a dreamt-of flowsheet
146 GUI, etc.
147
148 @return the 'language' of the note
149 */
150 const SymChar
151 Annotation::getLanguage() const{
152 asc_assert(GetNoteLanguage(n)!=NULL);
153 return SymChar(SCP(GetNoteLanguage(n)));
154 }
155
156 /**
157 @return the filename to which this note is assigned (where it was declared)
158 */
159 const char *
160 Annotation::getFilename() const{
161 return GetNoteFilename(n);
162 }
163
164 /**
165 @return the line number where this note was assigned
166 */
167 const int
168 Annotation::getLineNumber() const{
169 return GetNoteLineNum(n);
170 }
171
172 /**
173 @return the text content of this note (might be quite big, possibly)
174 */
175 const char *
176 Annotation::getText() const{
177 return BraceCharString(GetNoteText(n));
178 }
179
180 /**
181 @return the data type code for this note. Note sure what can be done with
182 this just yet.
183 */
184 const int
185 Annotation::getDataType() const{
186 return (int)GetNoteEnum(n);
187 }

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