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

Contents of /trunk/pygtk/dimensions.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 532 - (show annotations) (download) (as text)
Mon Apr 24 02:23:08 2006 UTC (14 years, 1 month ago) by johnpye
File MIME type: text/x-c++src
File size: 2202 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 using namespace std;
4
5 #include "units.h"
6 #include "dimensions.h"
7
8 #ifdef ASCXX_WORDY_BASE_DIMENSIONS
9 const string Dimensions::BASEUNITS[Dimensions::MAX_DIMS] = {
10 UNIT_BASE_MASS,UNIT_BASE_QUANTITY,UNIT_BASE_LENGTH, UNIT_BASE_TIME,
11 UNIT_BASE_TEMPERATURE, UNIT_BASE_CURRENCY, UNIT_BASE_ELECTRIC_CURRENT,
12 UNIT_BASE_LUMINOUS_INTENSITY, UNIT_BASE_PLANE_ANGLE, UNIT_BASE_SOLID_ANGLE
13 };
14 #else
15 // Preferred SI abbreviated dimension names
16 const string Dimensions::BASEUNITS[Dimensions::MAX_DIMS] = {
17 "kg","mol","m","s","K","USD","A",
18 "cd", "rad", "sr"
19 };
20 #endif
21
22 const string
23 Dimensions::getBaseUnit(const unsigned &i){
24 return BASEUNITS[i];
25 }
26
27 Dimensions::Dimensions(){
28 // This ctor needs to exist for SWIG to be happy. *shrug*.
29 throw runtime_error("Can't create Dimensions like this");
30 }
31
32 Dimensions::Dimensions(const Dimensions &old) : d(old.d){
33 // nothing else
34 }
35
36 Dimensions::Dimensions(const dim_type *d) : d(d){
37 // nothing else
38 }
39
40 const dim_type *
41 Dimensions::getInternalType() const{
42 return d;
43 }
44
45 // Comparison operators
46
47 const bool
48 Dimensions::operator<(const Dimensions &d1) const{
49 return -1 == CmpDimen(d, d1.getInternalType());
50 }
51
52 const bool
53 Dimensions::operator==(const Dimensions &d1) const{
54 ERROR_REPORTER_START_HERE(ASC_USER_NOTE);
55 FPRINTF(stderr,"Comparing dimensions; this=");
56 PrintDimen(stderr,d);
57 FPRINTF(stderr,", d1=");
58 PrintDimen(stderr,d1.getInternalType());
59 FPRINTF(stderr,": comparison result=%d",CmpDimen(d,d1.getInternalType()));
60 error_reporter_end_flush();
61 if(CmpDimen(d, d1.getInternalType()) == 0)return true;
62 return false;
63 }
64
65 const bool
66 Dimensions::operator!=(const Dimensions &d1) const{
67 return 0 != CmpDimen(d, d1.getInternalType());
68 }
69
70 const bool
71 Dimensions::isDimensionless() const{
72 return d==Dimensionless();
73 }
74
75 const bool
76 Dimensions::isWild() const{
77 return IsWild(d);
78 }
79
80
81 /**
82 Get at the internal data structure: find the index of each fundamental dimension
83 */
84 const FRACPART
85 Dimensions::getFractionNumerator(const unsigned &i) const{
86 return Numerator( GetDimFraction(*d,i) );
87 }
88
89 const FRACPART
90 Dimensions::getFractionDenominator(const unsigned &i) const{
91 return Denominator( GetDimFraction(*d,i) );
92 }

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