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

Contents of /trunk/pygtk/units.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 532 - (show annotations) (download) (as text)
Mon Apr 24 02:23:08 2006 UTC (13 years, 11 months ago) by johnpye
File MIME type: text/x-c++src
File size: 1375 byte(s)
Removed 'interface' directory in trunk/pygtk/interface (moved everything up a level)
Made corresponding changes to SCons* and spec files.
1 #include <iostream>
2 #include <stdexcept>
3 #include <sstream>
4 using namespace std;
5
6 #include "units.h"
7 #include "dimensions.h"
8
9 UnitsM::UnitsM(){
10 /// ctor required to keep SWIG happy. don't use it though.
11 throw runtime_error("Can't create new Units like this");
12 }
13
14 UnitsM::UnitsM(const struct Units *u) : u(u){
15 // nothing else
16 }
17
18 /**
19 Parse a units string, create a new UnitsM object from the string.
20
21 UnitsM doesn't allocate any storage so it's OK to throw
22 an exception in a ctor
23 */
24 UnitsM::UnitsM(const char *units){
25 const struct Units *u = LookupUnits(units);
26 if(u==NULL){
27 //cerr << "About to create new units '" << units << "'" << endl;
28 long unsigned pos;
29 int err;
30 u = FindOrDefineUnits(units, &pos, &err);
31 if(u==NULL){
32 char **errv = UnitsExplainError(units, err, pos);
33 stringstream ss;
34 ss << "Error parsing units: " << errv[0] << endl << errv[1] << endl << errv[2];
35 throw runtime_error(ss.str());
36 }
37 }/*else{
38 cerr << "Units '" << units << "' were found in lookup" << endl;
39 }*/
40 this->u = u;
41 }
42
43 const struct Units *
44 UnitsM::getInternalType() const{
45 return u;
46 }
47
48 const SymChar
49 UnitsM::getName() const{
50 return SymChar(SCP( UnitsDescription(u) ));
51 }
52
53 const Dimensions
54 UnitsM::getDimensions() const{
55 const dim_type *d = UnitsDimensions(u);
56 return Dimensions(d);
57 }
58
59 const double
60 UnitsM::getConversion() const{
61 return UnitsConvFactor(u);
62 }

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