1 |
#include <stdexcept> |
2 |
using namespace std; |
3 |
|
4 |
extern "C"{ |
5 |
#include <ascend/compiler/cmpfunc.h> |
6 |
} |
7 |
|
8 |
#include "symchar.h" |
9 |
|
10 |
/* |
11 |
SymChar::SymChar(){ |
12 |
throw runtime_error("Can't create empty SymChar"); |
13 |
} |
14 |
*/ |
15 |
SymChar::SymChar(const SymChar &old) : sc(old.sc){ |
16 |
// nothing else |
17 |
} |
18 |
|
19 |
SymChar::SymChar(const string &name){ |
20 |
sc = AddSymbol(name.c_str()); |
21 |
} |
22 |
|
23 |
|
24 |
SymChar::SymChar(const char *name){ |
25 |
sc = AddSymbol(name); |
26 |
} |
27 |
|
28 |
SymChar::SymChar(const symchar *hash) : sc(sc){ |
29 |
cerr << "CREATING SymChar from symchar*, '" << toString() << "'" << endl; |
30 |
// nothing else |
31 |
} |
32 |
|
33 |
SymChar::SymChar(const struct InstanceName &in) { |
34 |
|
35 |
//cerr << "Symchar(InstanceName) called" << endl; |
36 |
|
37 |
if(InstanceNameType(in) == IntArrayIndex){ |
38 |
char n[50]; |
39 |
snprintf(n,50,"%ld",InstanceIntIndex(in)); |
40 |
sc = AddSymbol(n); |
41 |
}else{ |
42 |
sc = InstanceNameStr(in); |
43 |
} |
44 |
|
45 |
if(sc==NULL){ |
46 |
throw runtime_error("Invalid name in SymChar::SymChar(InstanceName)"); |
47 |
} |
48 |
//cerr << "CREATING SymChar from InstanceName, '" << getName() << "'" << endl; |
49 |
} |
50 |
|
51 |
const char * |
52 |
SymChar::toString() const{ |
53 |
return SCP(sc); |
54 |
} |
55 |
|
56 |
bool |
57 |
SymChar::operator==(const SymChar &other) const{ |
58 |
if(sc == other.sc)return true; |
59 |
return false; |
60 |
} |
61 |
|
62 |
bool |
63 |
SymChar::operator<(const SymChar &other) const{ |
64 |
return CmpSymchar(sc,other.sc) == -1; |
65 |
} |
66 |
|
67 |
const symchar * |
68 |
SymChar::getInternalType() const{ |
69 |
return sc; |
70 |
} |
71 |
|
72 |
ostream& operator << (ostream& os, const SymChar& s){ |
73 |
return os << s.toString(); |
74 |
} |