WSF
WsfPProxyHash.hpp
Go to the documentation of this file.
1// ****************************************************************************
2// CUI
3//
4// The Advanced Framework for Simulation, Integration, and Modeling (AFSIM)
5//
6// Copyright 2003-2015 The Boeing Company. All rights reserved.
7//
8// The use, dissemination or disclosure of data in this file is subject to
9// limitation or restriction. See accompanying README and LICENSE for details.
10// ****************************************************************************
11// ****************************************************************************
12// Updated by Infoscitex, a DCS Company.
13// ****************************************************************************
14
15#ifndef WSFPPROXYHASH_HPP
16#define WSFPPROXYHASH_HPP
17#include <cstring>
18
19#include "UtCast.hpp"
20#include "UtSHA.hpp"
21
26{
27public:
29 : mIsDigest(false)
30 {
31 mDigestOrBuffer.mBuffer.mPointer = nullptr;
32 mDigestOrBuffer.mBuffer.mSize = 0;
33 }
34 WsfPProxyHash(const void* aBufferPtr, size_t aBufferSize)
35 {
36 mIsDigest = false;
37 mDigestOrBuffer.mBuffer.mPointer = aBufferPtr;
38 mDigestOrBuffer.mBuffer.mSize = ut::cast_to_int(aBufferSize);
39 }
41 {
42 mIsDigest = true;
43 mDigestOrBuffer.mDigest = aDigest;
44 }
45 WsfPProxyHash(const WsfPProxyHash& aSrc) { (*this) = aSrc; }
47 {
48 mIsDigest = aRhs.mIsDigest;
49 if (mIsDigest)
50 {
51 mDigestOrBuffer.mDigest = aRhs.mDigestOrBuffer.mDigest;
52 }
53 else
54 {
55 mDigestOrBuffer.mBuffer = aRhs.mDigestOrBuffer.mBuffer;
56 }
57 return *this;
58 }
59 bool operator==(const WsfPProxyHash& aRhs) const
60 {
61 int size = GetSize();
62 if (size != aRhs.GetSize())
63 {
64 return false;
65 }
66 return memcmp(GetPointer(), aRhs.GetPointer(), size) == 0;
67 }
68 bool operator!=(const WsfPProxyHash& aRhs) const { return !(*this == aRhs); }
69 bool operator<(const WsfPProxyHash& aRhs) const
70 {
71 int s1 = GetSize();
72 int s2 = aRhs.GetSize();
73 if (s1 < s2)
74 {
75 return true;
76 }
77 if (s1 > s2)
78 {
79 return false;
80 }
81 return memcmp(GetPointer(), aRhs.GetPointer(), s1) < 0;
82 }
83
84 int AddData(UtSHA& aSha) const
85 {
86 int size = GetSize();
87 if (size)
88 {
89 aSha.AddData((const char*)GetPointer(), size);
90 }
91 return size;
92 }
93 const void* GetPointer() const
94 {
95 return mIsDigest ? &mDigestOrBuffer.mDigest.mBytes[0] : mDigestOrBuffer.mBuffer.mPointer;
96 }
97 int GetSize() const { return mIsDigest ? UtSHA_Digest::cBUFFER_SIZE : mDigestOrBuffer.mBuffer.mSize; }
99
100private:
101 struct Buffer
102 {
103 const void* mPointer;
104 int mSize;
105 };
106 union DigestOrBuffer
107 {
108 Buffer mBuffer;
109 UtSHA_Digest mDigest;
110 };
111 DigestOrBuffer mDigestOrBuffer;
112};
113
114#endif
Container for a UtSHA Digest.
Definition UtSHA.hpp:88
@ cBUFFER_SIZE
Definition UtSHA.hpp:93
Definition UtSHA.hpp:28
void AddData(char const *aData, size_t aDataLength)
Definition UtSHA.cpp:50
bool operator!=(const WsfPProxyHash &aRhs) const
Definition WsfPProxyHash.hpp:68
WsfPProxyHash(const WsfPProxyHash &aSrc)
Definition WsfPProxyHash.hpp:45
WsfPProxyHash & operator=(const WsfPProxyHash &aRhs)
Definition WsfPProxyHash.hpp:46
bool mIsDigest
Definition WsfPProxyHash.hpp:98
int GetSize() const
Definition WsfPProxyHash.hpp:97
WsfPProxyHash()
Definition WsfPProxyHash.hpp:28
const void * GetPointer() const
Definition WsfPProxyHash.hpp:93
bool operator==(const WsfPProxyHash &aRhs) const
Definition WsfPProxyHash.hpp:59
WsfPProxyHash(const void *aBufferPtr, size_t aBufferSize)
Definition WsfPProxyHash.hpp:34
int AddData(UtSHA &aSha) const
Add this block of data to a SHA run.
Definition WsfPProxyHash.hpp:84
WsfPProxyHash(const UtSHA_Digest &aDigest)
Definition WsfPProxyHash.hpp:40
bool operator<(const WsfPProxyHash &aRhs) const
Definition WsfPProxyHash.hpp:69
Copyrights Multiple, All Rights Reserved