0030895: Coding Rules - specify std namespace explicitly for std::cout and streams
[occt.git] / src / Units / Units_Unit.cxx
1 // Created on: 1992-06-24
2 // Created by: Gilles DEBARBOUILLE
3 // Copyright (c) 1992-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17
18 #include <Standard_Type.hxx>
19 #include <TCollection_AsciiString.hxx>
20 #include <TCollection_HAsciiString.hxx>
21 #include <TColStd_HSequenceOfHAsciiString.hxx>
22 #include <Units.hxx>
23 #include <Units_Quantity.hxx>
24 #include <Units_Token.hxx>
25 #include <Units_Unit.hxx>
26 #include <Units_UnitsDictionary.hxx>
27
28 IMPLEMENT_STANDARD_RTTIEXT(Units_Unit,Standard_Transient)
29
30 //=======================================================================
31 //function : Units_Unit
32 //purpose  : 
33 //=======================================================================
34 Units_Unit::Units_Unit(const Standard_CString aname,
35                        const Standard_CString asymbol,
36                        const Standard_Real avalue,
37                        const Handle(Units_Quantity)& aquantity)
38 {
39   thename       = new TCollection_HAsciiString(aname);
40   thevalue      = avalue;
41   thequantity = aquantity;
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                        const Standard_CString asymbol)
54 {
55   thename       = new TCollection_HAsciiString(aname);
56   thevalue      = 0.;
57   Handle(TCollection_HAsciiString) symbol = new TCollection_HAsciiString(asymbol);
58   thesymbolssequence = new TColStd_HSequenceOfHAsciiString();
59   thesymbolssequence->Prepend(symbol);
60 }
61
62 //=======================================================================
63 //function : Units_Unit
64 //purpose  : 
65 //=======================================================================
66
67 Units_Unit::Units_Unit(const Standard_CString aname)
68 {
69   thename  = new TCollection_HAsciiString(aname);
70   thevalue = 0.;
71   thesymbolssequence = new TColStd_HSequenceOfHAsciiString();
72 }
73
74 //=======================================================================
75 //function : Symbol
76 //purpose  : 
77 //=======================================================================
78
79 void Units_Unit::Symbol(const Standard_CString asymbol)
80 {
81   Handle(TCollection_HAsciiString) symbol = new TCollection_HAsciiString(asymbol);
82   thesymbolssequence->Append(symbol);
83 }
84
85 //=======================================================================
86 //function : Token
87 //purpose  : 
88 //=======================================================================
89
90 Handle(Units_Token) Units_Unit::Token() const
91 {
92   TCollection_AsciiString string = thesymbolssequence->Value(1)->String();
93   return new Units_Token(string.ToCString()," ",thevalue,thequantity->Dimensions());
94 }
95
96 //=======================================================================
97 //function : IsEqual
98 //purpose  : 
99 //=======================================================================
100
101 Standard_Boolean Units_Unit::IsEqual(const Standard_CString astring) const
102 {
103   Standard_Integer index;
104   TCollection_AsciiString symbol;
105
106   for(index=1;index<=thesymbolssequence->Length();index++)
107     {
108       symbol = thesymbolssequence->Value(index)->String();
109       if(symbol == astring) return Standard_True;
110     }
111
112   return Standard_False;
113 }
114
115 //=======================================================================
116 //function : Dump
117 //purpose  : 
118 //=======================================================================
119
120 void Units_Unit::Dump(const Standard_Integer /*ashift*/,
121                       const Standard_Integer) const
122 {
123   Standard_Integer index;
124   TCollection_AsciiString string;
125
126 //  int i;
127 //  for(i=0; i<ashift; i++)std::cout<<"  ";
128   for(index=1;index<=thesymbolssequence->Length();index++)
129     {
130       string = thesymbolssequence->Value(index)->String();
131       if(index != 1) std::cout << " or " ;
132       std::cout<<"\""<<string.ToCString()<<"\"";
133     }
134   std::cout<< "         Name:  " <<Name().ToCString()<<"                (= " << thevalue << " SI)" <<std::endl;
135 }
136
137 //=======================================================================
138 //function : operator ==
139 //purpose  : 
140 //=======================================================================
141
142 Standard_Boolean operator ==(const Handle(Units_Unit)& aunit,const Standard_CString astring)
143 {
144   return aunit->IsEqual(astring);
145 }