0020716: Eliminate usage of "config.h" header file
[occt.git] / src / Standard / Standard_HashCode.cxx
CommitLineData
b311480e 1// Copyright (c) 1998-1999 Matra Datavision
973c2be1 2// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 3//
973c2be1 4// This file is part of Open CASCADE Technology software library.
b311480e 5//
d5f74e42 6// This library is free software; you can redistribute it and/or modify it under
7// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 8// by the Free Software Foundation, with special exception defined in the file
9// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10// distribution for complete text of the license and disclaimer of any warranty.
b311480e 11//
973c2be1 12// Alternatively, this file may be used under the terms of Open CASCADE
13// commercial license or contractual agreement.
b311480e 14
7fd59977 15#include <Standard_Transient.hxx>
16#include <Standard_Persistent.hxx>
17#include <Standard_Type.hxx>
18#include <Standard_RangeError.hxx>
19
20//============================================================================
21Standard_EXPORT Standard_Integer HashCode(const Standard_Address me,const Standard_Integer Upper,const Handle(Standard_Type)& aType)
22{
23 char *mecharPtr;
24 Standard_Integer *meintPtr = (Standard_Integer *) me;
25 Standard_Integer aHashCode, aRest, i, aSize = aType->Size();
26
27 Standard_RangeError_Raise_if (Upper < 1,
28 "Try to apply HashCode method with negative or null argument.");
29
30 aRest = aSize % sizeof(Standard_Integer);
31
32 aHashCode = 0;
33
34 if (aSize == 0)
35 aHashCode = (Standard_Integer) ptrdiff_t(me);
36
37
38 for (i = 0; (unsigned int ) i < aSize / sizeof(Standard_Integer); i++)
39 {
40 aHashCode = aHashCode ^ *meintPtr;
41 meintPtr++;
42 }
43
44 mecharPtr = (char *) meintPtr;
45
46 for (i = 0; i < aRest; i++)
47 {
48 aHashCode = aHashCode ^ *mecharPtr;
49 mecharPtr++;
50 }
51
52
53 return HashCode( aHashCode , Upper) ;
54}
55
56//============================================================================
57Standard_EXPORT Standard_Integer HashCode (const Handle(Standard_Transient)& me,
58 const Standard_Integer Upper )
59{
60 Standard_RangeError_Raise_if (Upper < 1,
61 "Try to apply HashCode method "
62 "with negative or null argument.");
63
64 const Standard_Integer I = (Standard_Integer) ptrdiff_t(me.operator->());
65 return HashCode( I , Upper ) ;
66}
67
68//============================================================================
69Standard_EXPORT Standard_Integer HashCode(const Handle(Standard_Persistent)& me,
70 const Standard_Integer Upper )
71{
72 Standard_RangeError_Raise_if (Upper < 1,
73 "Try to apply HashCode method "
74 "with negative or null argument.");
75
76 const Standard_Integer I = (Standard_Integer) ptrdiff_t(me.operator->());
77 return HashCode( I , Upper) ;
78}
79