Merge pull request #5 from intothevoid/master
[KDIS.git] / KDIS / KDIS / PDU / Simulation_Management / Start_Resume_PDU.cpp
blob5acc0664d71b53b1699f22a0bed5a60ea66897d1
1 /*********************************************************************
2 Copyright 2013 Karl Jones
3 All rights reserved.
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
8 1. Redistributions of source code must retain the above copyright notice, this
9 list of conditions and the following disclaimer.
10 2. Redistributions in binary form must reproduce the above copyright notice,
11 this list of conditions and the following disclaimer in the documentation
12 and/or other materials provided with the distribution.
14 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
15 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
18 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 For Further Information Please Contact me at
26 Karljj1@yahoo.com
27 http://p.sf.net/kdis/UserGuide
28 *********************************************************************/
30 #include "./Start_Resume_PDU.h"
32 //////////////////////////////////////////////////////////////////////////
34 using namespace std;
35 using namespace KDIS;
36 using namespace PDU;
37 using namespace DATA_TYPE;
38 using namespace ENUMS;
39 using namespace UTILS;
41 //////////////////////////////////////////////////////////////////////////
42 // public:
43 //////////////////////////////////////////////////////////////////////////
45 Start_Resume_PDU::Start_Resume_PDU() :
46 m_ui32RequestID( 0 )
48 m_ui8PDUType = Start_Resume_PDU_Type;
49 m_ui16PDULength = START_RESUME_PDU_SIZE;
52 //////////////////////////////////////////////////////////////////////////
54 Start_Resume_PDU::Start_Resume_PDU( const Header & H ) :
55 Simulation_Management_Header( H ),
56 m_ui32RequestID( 0 )
60 //////////////////////////////////////////////////////////////////////////
62 Start_Resume_PDU::Start_Resume_PDU( KDataStream & stream )
64 Decode( stream, false );
67 //////////////////////////////////////////////////////////////////////////
69 Start_Resume_PDU::Start_Resume_PDU( const Header & H, KDataStream & stream ) :
70 Simulation_Management_Header( H )
72 Decode( stream, true );
75 //////////////////////////////////////////////////////////////////////////
77 Start_Resume_PDU::Start_Resume_PDU( const EntityIdentifier & ReceivingEntity, const EntityIdentifier & SupplyingEntity,
78 const ClockTime & RealWorldTime, const ClockTime & SimTime, KUINT32 ReqID ) :
79 Simulation_Management_Header( ReceivingEntity, SupplyingEntity ),
80 m_RealWorldTime( RealWorldTime ),
81 m_SimTime( SimTime ),
82 m_ui32RequestID( ReqID )
84 m_ui8PDUType = Start_Resume_PDU_Type;
85 m_ui16PDULength = START_RESUME_PDU_SIZE;
88 //////////////////////////////////////////////////////////////////////////
90 Start_Resume_PDU::Start_Resume_PDU( const Simulation_Management_Header & SimMgrHeader, const ClockTime & RealWorldTime,
91 const ClockTime & SimTime, KUINT32 ReqID ) :
92 Simulation_Management_Header( SimMgrHeader ),
93 m_RealWorldTime( RealWorldTime ),
94 m_SimTime( SimTime ),
95 m_ui32RequestID( ReqID )
97 m_ui8PDUType = Start_Resume_PDU_Type;
98 m_ui16PDULength = START_RESUME_PDU_SIZE;
101 //////////////////////////////////////////////////////////////////////////
103 Start_Resume_PDU::~Start_Resume_PDU()
107 //////////////////////////////////////////////////////////////////////////
109 void Start_Resume_PDU::SetRealWorldTime( const ClockTime & T )
111 m_RealWorldTime = T;
114 //////////////////////////////////////////////////////////////////////////
116 const ClockTime & Start_Resume_PDU::GetRealWorldTime() const
118 return m_RealWorldTime;
121 //////////////////////////////////////////////////////////////////////////
123 ClockTime & Start_Resume_PDU::GetRealWorldTime()
125 return m_RealWorldTime;
128 //////////////////////////////////////////////////////////////////////////
130 void Start_Resume_PDU::SetSimulationTime( const ClockTime & T )
132 m_SimTime = T;
135 //////////////////////////////////////////////////////////////////////////
137 const ClockTime & Start_Resume_PDU::GetSimulationTime() const
139 return m_SimTime;
142 //////////////////////////////////////////////////////////////////////////
144 ClockTime & Start_Resume_PDU::GetSimulationTime()
146 return m_SimTime;
149 //////////////////////////////////////////////////////////////////////////
151 void Start_Resume_PDU::SetRequestID( KUINT32 ID )
153 m_ui32RequestID = ID;
156 //////////////////////////////////////////////////////////////////////////
158 KUINT32 Start_Resume_PDU::GetRequestID() const
160 return m_ui32RequestID;
163 //////////////////////////////////////////////////////////////////////////
165 KString Start_Resume_PDU::GetAsString() const
167 KStringStream ss;
169 ss << Header::GetAsString()
170 << "-Start/Resume PDU-\n"
171 << Simulation_Management_Header::GetAsString()
172 << "Real World Time:\n"
173 << IndentString( m_RealWorldTime.GetAsString(), 1 )
174 << "Simulation Time:\n"
175 << IndentString( m_SimTime.GetAsString(), 1 )
176 << "Request ID: " << m_ui32RequestID
177 << "\n";
179 return ss.str();
182 //////////////////////////////////////////////////////////////////////////
184 void Start_Resume_PDU::Decode( KDataStream & stream, bool ignoreHeader /*= true*/ )
186 if( ( stream.GetBufferSize() + ( ignoreHeader ? Header::HEADER6_PDU_SIZE : 0 ) ) < START_RESUME_PDU_SIZE )throw KException( __FUNCTION__, NOT_ENOUGH_DATA_IN_BUFFER );
188 Simulation_Management_Header::Decode( stream, ignoreHeader );
190 stream >> KDIS_STREAM m_RealWorldTime
191 >> KDIS_STREAM m_SimTime
192 >> m_ui32RequestID;
195 //////////////////////////////////////////////////////////////////////////
197 KDataStream Start_Resume_PDU::Encode() const
199 KDataStream stream;
201 Start_Resume_PDU::Encode( stream );
203 return stream;
206 //////////////////////////////////////////////////////////////////////////
208 void Start_Resume_PDU::Encode( KDataStream & stream ) const
210 Simulation_Management_Header::Encode( stream );
211 stream << KDIS_STREAM m_RealWorldTime
212 << KDIS_STREAM m_SimTime
213 << m_ui32RequestID;
216 //////////////////////////////////////////////////////////////////////////
218 KBOOL Start_Resume_PDU::operator == ( const Start_Resume_PDU & Value ) const
220 if( Simulation_Management_Header::operator !=( Value ) ) return false;
221 if( m_RealWorldTime != Value.m_RealWorldTime ) return false;
222 if( m_SimTime != Value.m_SimTime ) return false;
223 if( m_ui32RequestID != Value.m_ui32RequestID ) return false;
224 return true;
227 //////////////////////////////////////////////////////////////////////////
229 KBOOL Start_Resume_PDU::operator != ( const Start_Resume_PDU & Value ) const
231 return !( *this == Value );
234 //////////////////////////////////////////////////////////////////////////