summaryrefslogtreecommitdiff
path: root/src/Units/Units_Unit.cxx
blob: 543c42ff1f6a00d0a4991b8a4e1ad99d2bfaa31e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// File:	Units_Unit.cxx
// Created:	Wed Jun 24 12:49:08 1992
// Author:	Gilles DEBARBOUILLE
//		<gde@phobox>


#include <Units_Unit.ixx>
#include <Units.hxx>
#include <Units_UnitsDictionary.hxx>
#include <TCollection_HAsciiString.hxx>
#include <TCollection_AsciiString.hxx>
#include <TColStd_HSequenceOfHAsciiString.hxx>

//=======================================================================
//function : Units_Unit
//purpose  : 
//=======================================================================

Units_Unit::Units_Unit(const Standard_CString aname,
		       const Standard_CString asymbol,
		       const Standard_Real avalue,
		       const Handle(Units_Quantity)& aquantity)
{
  thename       = new TCollection_HAsciiString(aname);
  thevalue      = avalue;
  thequantity = aquantity;
  Handle(TCollection_HAsciiString) symbol = new TCollection_HAsciiString(asymbol);
  thesymbolssequence = new TColStd_HSequenceOfHAsciiString();
  thesymbolssequence->Prepend(symbol);
}

//=======================================================================
//function : Units_Unit
//purpose  : 
//=======================================================================

Units_Unit::Units_Unit(const Standard_CString aname,
		       const Standard_CString asymbol)
{
  thename       = new TCollection_HAsciiString(aname);
  thevalue      = 0.;
  Handle(TCollection_HAsciiString) symbol = new TCollection_HAsciiString(asymbol);
  thesymbolssequence = new TColStd_HSequenceOfHAsciiString();
  thesymbolssequence->Prepend(symbol);
}

//=======================================================================
//function : Units_Unit
//purpose  : 
//=======================================================================

Units_Unit::Units_Unit(const Standard_CString aname)
{
  thename  = new TCollection_HAsciiString(aname);
  thevalue = 0.;
  thesymbolssequence = new TColStd_HSequenceOfHAsciiString();
}

//=======================================================================
//function : Symbol
//purpose  : 
//=======================================================================

void Units_Unit::Symbol(const Standard_CString asymbol)
{
  Handle(TCollection_HAsciiString) symbol = new TCollection_HAsciiString(asymbol);
  thesymbolssequence->Append(symbol);
}

//=======================================================================
//function : Token
//purpose  : 
//=======================================================================

Handle(Units_Token) Units_Unit::Token() const
{
  TCollection_AsciiString string = thesymbolssequence->Value(1)->String();
  return new Units_Token(string.ToCString()," ",thevalue,thequantity->Dimensions());
}

//=======================================================================
//function : IsEqual
//purpose  : 
//=======================================================================

Standard_Boolean Units_Unit::IsEqual(const Standard_CString astring) const
{
  Standard_Integer index;
  TCollection_AsciiString symbol;

  for(index=1;index<=thesymbolssequence->Length();index++)
    {
      symbol = thesymbolssequence->Value(index)->String();
      if(symbol == astring) return Standard_True;
    }

  return Standard_False;
}

//=======================================================================
//function : Dump
//purpose  : 
//=======================================================================

void Units_Unit::Dump(const Standard_Integer /*ashift*/,
		      const Standard_Integer) const
{
  Standard_Integer index;
  TCollection_AsciiString string;

//  int i;
//  for(i=0; i<ashift; i++)cout<<"  ";
  for(index=1;index<=thesymbolssequence->Length();index++)
    {
      string = thesymbolssequence->Value(index)->String();
      if(index != 1) cout << " or " ;
      cout<<"\""<<string.ToCString()<<"\"";
    }
  cout<< "		Name:  " <<Name().ToCString()<<"		(= " << thevalue << " SI)" <<endl;
}

//=======================================================================
//function : operator ==
//purpose  : 
//=======================================================================

Standard_Boolean operator ==(const Handle(Units_Unit)& aunit,const Standard_CString astring)
{
  return aunit->IsEqual(astring);
}