0022627: Change OCCT memory management defaults
[occt.git] / src / Units / Units_Unit.cxx
1 // File:        Units_Unit.cxx
2 // Created:     Wed Jun 24 12:49:08 1992
3 // Author:      Gilles DEBARBOUILLE
4 //              <gde@phobox>
5
6
7 #include <Units_Unit.ixx>
8 #include <Units.hxx>
9 #include <Units_UnitsDictionary.hxx>
10 #include <TCollection_HAsciiString.hxx>
11 #include <TCollection_AsciiString.hxx>
12 #include <TColStd_HSequenceOfHAsciiString.hxx>
13
14 //=======================================================================
15 //function : Units_Unit
16 //purpose  : 
17 //=======================================================================
18
19 Units_Unit::Units_Unit(const Standard_CString aname,
20                        const Standard_CString asymbol,
21                        const Standard_Real avalue,
22                        const Handle(Units_Quantity)& aquantity)
23 {
24   thename       = new TCollection_HAsciiString(aname);
25   thevalue      = avalue;
26   thequantity = aquantity;
27   Handle(TCollection_HAsciiString) symbol = new TCollection_HAsciiString(asymbol);
28   thesymbolssequence = new TColStd_HSequenceOfHAsciiString();
29   thesymbolssequence->Prepend(symbol);
30 }
31
32 //=======================================================================
33 //function : Units_Unit
34 //purpose  : 
35 //=======================================================================
36
37 Units_Unit::Units_Unit(const Standard_CString aname,
38                        const Standard_CString asymbol)
39 {
40   thename       = new TCollection_HAsciiString(aname);
41   thevalue      = 0.;
42   Handle(TCollection_HAsciiString) symbol = new TCollection_HAsciiString(asymbol);
43   thesymbolssequence = new TColStd_HSequenceOfHAsciiString();
44   thesymbolssequence->Prepend(symbol);
45 }
46
47 //=======================================================================
48 //function : Units_Unit
49 //purpose  : 
50 //=======================================================================
51
52 Units_Unit::Units_Unit(const Standard_CString aname)
53 {
54   thename  = new TCollection_HAsciiString(aname);
55   thevalue = 0.;
56   thesymbolssequence = new TColStd_HSequenceOfHAsciiString();
57 }
58
59 //=======================================================================
60 //function : Symbol
61 //purpose  : 
62 //=======================================================================
63
64 void Units_Unit::Symbol(const Standard_CString asymbol)
65 {
66   Handle(TCollection_HAsciiString) symbol = new TCollection_HAsciiString(asymbol);
67   thesymbolssequence->Append(symbol);
68 }
69
70 //=======================================================================
71 //function : Token
72 //purpose  : 
73 //=======================================================================
74
75 Handle(Units_Token) Units_Unit::Token() const
76 {
77   TCollection_AsciiString string = thesymbolssequence->Value(1)->String();
78   return new Units_Token(string.ToCString()," ",thevalue,thequantity->Dimensions());
79 }
80
81 //=======================================================================
82 //function : IsEqual
83 //purpose  : 
84 //=======================================================================
85
86 Standard_Boolean Units_Unit::IsEqual(const Standard_CString astring) const
87 {
88   Standard_Integer index;
89   TCollection_AsciiString symbol;
90
91   for(index=1;index<=thesymbolssequence->Length();index++)
92     {
93       symbol = thesymbolssequence->Value(index)->String();
94       if(symbol == astring) return Standard_True;
95     }
96
97   return Standard_False;
98 }
99
100 //=======================================================================
101 //function : Dump
102 //purpose  : 
103 //=======================================================================
104
105 void Units_Unit::Dump(const Standard_Integer /*ashift*/,
106                       const Standard_Integer) const
107 {
108   Standard_Integer index;
109   TCollection_AsciiString string;
110
111 //  int i;
112 //  for(i=0; i<ashift; i++)cout<<"  ";
113   for(index=1;index<=thesymbolssequence->Length();index++)
114     {
115       string = thesymbolssequence->Value(index)->String();
116       if(index != 1) cout << " or " ;
117       cout<<"\""<<string.ToCString()<<"\"";
118     }
119   cout<< "              Name:  " <<Name().ToCString()<<"                (= " << thevalue << " SI)" <<endl;
120 }
121
122 //=======================================================================
123 //function : operator ==
124 //purpose  : 
125 //=======================================================================
126
127 Standard_Boolean operator ==(const Handle(Units_Unit)& aunit,const Standard_CString astring)
128 {
129   return aunit->IsEqual(astring);
130 }