1 // Created on: 1992-06-24
2 // Created by: Gilles DEBARBOUILLE
3 // Copyright (c) 1992-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
23 #include <Units_Unit.ixx>
25 #include <Units_UnitsDictionary.hxx>
26 #include <TCollection_HAsciiString.hxx>
27 #include <TCollection_AsciiString.hxx>
28 #include <TColStd_HSequenceOfHAsciiString.hxx>
30 //=======================================================================
31 //function : Units_Unit
33 //=======================================================================
35 Units_Unit::Units_Unit(const Standard_CString aname,
36 const Standard_CString asymbol,
37 const Standard_Real avalue,
38 const Handle(Units_Quantity)& aquantity)
40 thename = new TCollection_HAsciiString(aname);
42 thequantity = aquantity;
43 Handle(TCollection_HAsciiString) symbol = new TCollection_HAsciiString(asymbol);
44 thesymbolssequence = new TColStd_HSequenceOfHAsciiString();
45 thesymbolssequence->Prepend(symbol);
48 //=======================================================================
49 //function : Units_Unit
51 //=======================================================================
53 Units_Unit::Units_Unit(const Standard_CString aname,
54 const Standard_CString asymbol)
56 thename = new TCollection_HAsciiString(aname);
58 Handle(TCollection_HAsciiString) symbol = new TCollection_HAsciiString(asymbol);
59 thesymbolssequence = new TColStd_HSequenceOfHAsciiString();
60 thesymbolssequence->Prepend(symbol);
63 //=======================================================================
64 //function : Units_Unit
66 //=======================================================================
68 Units_Unit::Units_Unit(const Standard_CString aname)
70 thename = new TCollection_HAsciiString(aname);
72 thesymbolssequence = new TColStd_HSequenceOfHAsciiString();
75 //=======================================================================
78 //=======================================================================
80 void Units_Unit::Symbol(const Standard_CString asymbol)
82 Handle(TCollection_HAsciiString) symbol = new TCollection_HAsciiString(asymbol);
83 thesymbolssequence->Append(symbol);
86 //=======================================================================
89 //=======================================================================
91 Handle(Units_Token) Units_Unit::Token() const
93 TCollection_AsciiString string = thesymbolssequence->Value(1)->String();
94 return new Units_Token(string.ToCString()," ",thevalue,thequantity->Dimensions());
97 //=======================================================================
100 //=======================================================================
102 Standard_Boolean Units_Unit::IsEqual(const Standard_CString astring) const
104 Standard_Integer index;
105 TCollection_AsciiString symbol;
107 for(index=1;index<=thesymbolssequence->Length();index++)
109 symbol = thesymbolssequence->Value(index)->String();
110 if(symbol == astring) return Standard_True;
113 return Standard_False;
116 //=======================================================================
119 //=======================================================================
121 void Units_Unit::Dump(const Standard_Integer /*ashift*/,
122 const Standard_Integer) const
124 Standard_Integer index;
125 TCollection_AsciiString string;
128 // for(i=0; i<ashift; i++)cout<<" ";
129 for(index=1;index<=thesymbolssequence->Length();index++)
131 string = thesymbolssequence->Value(index)->String();
132 if(index != 1) cout << " or " ;
133 cout<<"\""<<string.ToCString()<<"\"";
135 cout<< " Name: " <<Name().ToCString()<<" (= " << thevalue << " SI)" <<endl;
138 //=======================================================================
139 //function : operator ==
141 //=======================================================================
143 Standard_Boolean operator ==(const Handle(Units_Unit)& aunit,const Standard_CString astring)
145 return aunit->IsEqual(astring);