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

Contents of /trunk/pygtk/dimensions.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1702 - (show annotations) (download) (as text)
Sun Jan 6 03:45:33 2008 UTC (16 years, 5 months ago) by jpye
File MIME type: text/x-c++src
File size: 2095 byte(s)
Removed redundant base unit definitions now that compiler/units.h changed to SI abbrevs.
1 #include <iostream>
2 #include <stdexcept>
3 using namespace std;
4
5 #include "units.h"
6 #include "dimensions.h"
7
8 extern "C"{
9 #include <compiler/dimen_io.h>
10 }
11
12 const string Dimensions::BASEUNITS[Dimensions::MAX_DIMS] = {
13 UNIT_BASE_MASS,UNIT_BASE_QUANTITY,UNIT_BASE_LENGTH, UNIT_BASE_TIME,
14 UNIT_BASE_TEMPERATURE, UNIT_BASE_CURRENCY, UNIT_BASE_ELECTRIC_CURRENT,
15 UNIT_BASE_LUMINOUS_INTENSITY, UNIT_BASE_PLANE_ANGLE, UNIT_BASE_SOLID_ANGLE
16 };
17
18 const string
19 Dimensions::getBaseUnit(const unsigned &i){
20 return BASEUNITS[i];
21 }
22
23 Dimensions::Dimensions() : d(WildDimension()){
24 // nothing else
25 }
26
27 Dimensions::Dimensions(const Dimensions &old) : d(old.d){
28 // nothing else
29 }
30
31 Dimensions::Dimensions(const dim_type *d) : d(d){
32 // nothing else
33 }
34
35 const dim_type *
36 Dimensions::getInternalType() const{
37 return d;
38 }
39
40 // Comparison operators
41
42 const bool
43 Dimensions::operator<(const Dimensions &d1) const{
44 return -1 == CmpDimen(d, d1.getInternalType());
45 }
46
47 const bool
48 Dimensions::operator==(const Dimensions &d1) const{
49 /*
50 ERROR_REPORTER_START_HERE(ASC_USER_NOTE);
51 FPRINTF(stderr,"Comparing dimensions; this=");
52 PrintDimen(stderr,d);
53 FPRINTF(stderr,", d1=");
54 PrintDimen(stderr,d1.getInternalType());
55 FPRINTF(stderr,": comparison result=%d",CmpDimen(d,d1.getInternalType()));
56 error_reporter_end_flush();
57 */
58 if(CmpDimen(d, d1.getInternalType()) == 0)return true;
59 return false;
60 }
61
62 const bool
63 Dimensions::operator!=(const Dimensions &d1) const{
64 return 0 != CmpDimen(d, d1.getInternalType());
65 }
66
67 const bool
68 Dimensions::isDimensionless() const{
69 return d==Dimensionless();
70 }
71
72 const bool
73 Dimensions::isWild() const{
74 return IsWild(d);
75 }
76
77
78 /**
79 Get at the internal data structure: find the index of each fundamental dimension
80 */
81 const FRACPART
82 Dimensions::getFractionNumerator(const unsigned &i) const{
83 return Numerator( GetDimFraction(*d,i) );
84 }
85
86 const FRACPART
87 Dimensions::getFractionDenominator(const unsigned &i) const{
88 return Denominator( GetDimFraction(*d,i) );
89 }
90
91 const std::string
92 Dimensions::toString() const{
93 const char *s = WriteDimensionString(getInternalType());
94 return string(s);
95 }
96
97

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