b311480e |
1 | // Copyright (c) 1998-1999 Matra Datavision |
2 | // Copyright (c) 1999-2012 OPEN CASCADE SAS |
3 | // |
4 | // The content of this file is subject to the Open CASCADE Technology Public |
5 | // License Version 6.5 (the "License"). You may not use the content of this file |
6 | // except in compliance with the License. Please obtain a copy of the License |
7 | // at http://www.opencascade.org and read it completely before using this file. |
8 | // |
9 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its |
10 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. |
11 | // |
12 | // The Original Code and all software distributed under the License is |
13 | // distributed on an "AS IS" basis, without warranty of any kind, and the |
14 | // Initial Developer hereby disclaims all such warranties, including without |
15 | // limitation, any warranties of merchantability, fitness for a particular |
16 | // purpose or non-infringement. Please see the License for the specific terms |
17 | // and conditions governing the rights and limitations under the License. |
18 | |
7fd59977 |
19 | #ifdef HAVE_CONFIG_H |
20 | # include <config.h> |
21 | #endif |
22 | |
23 | #define OptJr 1 |
24 | |
25 | #include <Standard_ExtString.hxx> |
26 | #include <Standard_Type.hxx> |
27 | #include <Standard_String.hxx> |
28 | #ifndef _Standard_OStream_HeaderFile |
29 | #include <Standard_OStream.hxx> |
30 | #endif |
31 | |
32 | //============================================================================ |
33 | //==== ShallowDump : Writes a ExtString value. |
34 | //============================================================================ |
35 | Standard_EXPORT void ShallowDump (const Standard_ExtString Value, Standard_OStream& s) |
36 | { |
37 | s << hex << Value << " Standard_ExtString " << endl; |
38 | } |
39 | |
34781c33 |
40 | const Handle_Standard_Type& Standard_ExtString_Type_() |
7fd59977 |
41 | { |
42 | static Handle_Standard_Type _aType = |
43 | new Standard_Type("Standard_ExtString",sizeof(Standard_ExtString),0,NULL); |
44 | |
45 | return _aType; |
46 | } |
47 | |
48 | Standard_Integer HashCode (const Standard_ExtString Value, |
49 | const Standard_Integer Upper) |
50 | { |
51 | Standard_Integer aHashCode ; |
52 | Standard_Integer i = 0 ; |
53 | |
54 | #if OptJr |
55 | Standard_ExtString aValue ; |
56 | |
57 | // cout << "HashCode " << hex << Value << dec << endl ; |
58 | |
59 | if ((ptrdiff_t(Value) & 3 ) == 2) { |
60 | aHashCode = Value[ 0 ] ; |
61 | #if defined(WNT) || defined(DECOSF1) || defined(LININTEL) || defined(__FreeBSD__) |
62 | aHashCode = aHashCode << 16 ; |
63 | #endif |
64 | aValue = &Value[1] ; |
65 | } |
66 | else { |
67 | aHashCode = 0 ; |
68 | aValue = Value ; |
69 | } |
70 | |
71 | while ( ExtStringTestOfZero(((Standard_Integer *) aValue ) [ i ] ) ) { |
72 | // cout << i << " " << hex << aHashCode << " " << ((Standard_Integer *) aValue )[i] |
73 | // << dec << endl ; |
74 | aHashCode = aHashCode ^ ((Standard_Integer *) aValue ) [ i++ ] ; |
75 | } |
76 | while ( aValue[ i << 1 ] != 0 && aValue[( i << 1 ) + 1 ] != 0 ) { |
77 | // cout << i << " " << hex << aHashCode << " " << ((Standard_Integer *) aValue )[i] |
78 | // << dec << endl ; |
79 | aHashCode = aHashCode ^ ((Standard_Integer *) aValue ) [ i++ ] ; |
80 | } |
81 | if ( aValue[ i << 1 ] != 0 ) { |
82 | // cout << i << " " << hex << aHashCode << dec << endl ; |
83 | aHashCode = aHashCode ^ ((Standard_Integer *) aValue ) [ i ] ; |
84 | } |
85 | if ((ptrdiff_t(Value ) & 3) == 2) { |
86 | // cout << hex << aHashCode << dec << endl ; |
87 | aHashCode = (( aHashCode >> 16 ) & 0x0000ffff ) | |
88 | (( aHashCode << 16 ) & 0xffff0000 ) ; |
89 | } |
90 | // cout << i << " " << hex << aHashCode << dec << endl ; |
91 | |
92 | #else |
93 | char* charPtr = (char *)Value; |
94 | Standard_Integer pos = 0, |
95 | count, |
96 | *tmphash, |
97 | isend = 0; |
98 | char tabchar[20]; |
99 | |
100 | aHashCode = 0 ; |
101 | if (Value != NULL) { |
102 | while(charPtr[i] != 0 || charPtr[i + 1] != 0) { |
103 | |
104 | for (count = 0,pos = i; count < sizeof(Standard_Integer); count += 2) { |
105 | |
106 | if (charPtr[pos + count] == 0 && charPtr[pos + count + 1] == 0 || isend == 1) { |
107 | isend = 1; |
108 | tabchar[count] = '\0'; |
109 | tabchar[count + 1] = '\0'; |
110 | } |
111 | else { |
112 | tabchar[count] = charPtr[pos + count]; |
113 | tabchar[count + 1] = charPtr[pos + count + 1]; |
114 | } |
115 | i += 2; |
116 | } |
117 | tmphash = (Standard_Integer *)tabchar; |
118 | aHashCode = aHashCode ^ *tmphash; |
119 | } |
120 | } |
121 | #endif |
122 | |
123 | aHashCode = HashCode(aHashCode , Upper) ; |
124 | return aHashCode ; |
125 | } |