-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathVersion.cpp
100 lines (74 loc) · 2.11 KB
/
Version.cpp
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
// Version.cpp - Part of Helix
// Copyright (c) 2002 by Tom Weatherhead. All rights reserved.
// Started December 17, 2002
#include "Common.h"
CVersion::CVersion( unsigned int v1, unsigned int v2, unsigned int v3 )
: m_unPrimaryVersion( v1 ),
m_unSecondaryVersion( v2 ),
m_unTertiaryVersion( v3 )
{
}
CVersion::CVersion( FILE * pSrcFile )
{
ReadFromFile( pSrcFile );
}
void CVersion::ReadFromFile( FILE * pSrcFile )
{
unsigned int aunV[3];
const int knIntsRead = fread( aunV, sizeof( unsigned int ), 3, pSrcFile );
if( knIntsRead != 3 )
{
Signal();
ThrowHelixException( "Failure to read version from file." );
}
#ifdef BIG_ENDIAN
for( int i = 0; i < 3; ++i )
{
ByteSwapUnsignedInt( aunV[i] );
}
#endif
m_unPrimaryVersion = aunV[0];
m_unSecondaryVersion = aunV[1];
m_unTertiaryVersion = aunV[2];
}
void CVersion::WriteToFile( FILE * pDstFile ) const
{
int aunV[3];
aunV[0] = m_unPrimaryVersion;
aunV[1] = m_unSecondaryVersion;
aunV[2] = m_unTertiaryVersion;
#ifdef BIG_ENDIAN
for( int i = 0; i < 3; ++i )
{
ByteSwapUnsignedInt( aunV[i] );
}
#endif
const int knIntsWritten = fwrite( aunV, sizeof( unsigned int ), 3, pDstFile );
if( knIntsWritten != 3 )
{
Signal();
ThrowHelixException( "Failure to write version to file." );
}
}
void CVersion::Print( void ) const
{
printf( "%d.%d.%d", m_unPrimaryVersion, m_unSecondaryVersion, m_unTertiaryVersion );
}
bool CVersion::operator==( const CVersion & Src ) const
{
return(
m_unPrimaryVersion == Src.m_unPrimaryVersion &&
m_unSecondaryVersion == Src.m_unSecondaryVersion &&
m_unTertiaryVersion == Src.m_unTertiaryVersion );
}
bool CVersion::operator<( const CVersion & Src ) const
{
return(
m_unPrimaryVersion < Src.m_unPrimaryVersion ||
( m_unPrimaryVersion == Src.m_unPrimaryVersion &&
m_unSecondaryVersion < Src.m_unSecondaryVersion ) ||
( m_unPrimaryVersion == Src.m_unPrimaryVersion &&
m_unSecondaryVersion == Src.m_unSecondaryVersion &&
m_unTertiaryVersion < Src.m_unTertiaryVersion ) );
}
// **** End of File ****