chore: KDIS datatypes
[KDIS.git] / KDIS / DataTypes / BeamStatus.cpp
blob68973128658e39a9e1f1ffb8e825beb8766ed9b3
1 /*********************************************************************
2 Copyright 2017 Karl Jones
3 Dale Marchand
4 All rights reserved.
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions are met:
9 1. Redistributions of source code must retain the above copyright notice, this
10 list of conditions and the following disclaimer.
11 2. Redistributions in binary form must reproduce the above copyright notice,
12 this list of conditions and the following disclaimer in the documentation
13 and/or other materials provided with the distribution.
15 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
19 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 For Further Information Please Contact me at
27 Karljj1@yahoo.com
28 http://p.sf.net/kdis/UserGuide
29 *********************************************************************/
31 #include "./BeamStatus.h"
32 #include "Enums/EnumEmitter.h"
34 using namespace KDIS;
35 using namespace DATA_TYPE;
36 using namespace ENUMS;
37 using std::endl;
39 #if DIS_VERSION > 6
41 namespace
43 const int s_BeamStateBitmask = 0x1;
44 const int s_PaddingBitmask = 0xfe;
47 //////////////////////////////////////////////////////////////////////////
48 // Public:
49 //////////////////////////////////////////////////////////////////////////
51 BeamStatus::BeamStatus() :
52 DataTypeBase(),
53 m_ui8BeamStatus( 0u )
57 //////////////////////////////////////////////////////////////////////////
59 BeamStatus::BeamStatus( KDataStream & stream ) :
60 DataTypeBase(),
61 m_ui8BeamStatus( 0u )
63 Decode( stream );
66 //////////////////////////////////////////////////////////////////////////
68 BeamStatus::BeamStatus( BeamState BS ) :
69 DataTypeBase(),
70 m_ui8BeamStatus( BS & s_BeamStateBitmask)
74 //////////////////////////////////////////////////////////////////////////
76 BeamStatus::~BeamStatus()
80 //////////////////////////////////////////////////////////////////////////
82 void BeamStatus::SetBeamState( BeamState BS )
84 m_ui8BeamStatus = (BS & s_BeamStateBitmask);
87 //////////////////////////////////////////////////////////////////////////
89 BeamState BeamStatus::GetBeamState() const
91 return static_cast<BeamState>(m_ui8BeamStatus & s_BeamStateBitmask);
94 //////////////////////////////////////////////////////////////////////////
96 KString BeamStatus::GetAsString() const
98 KStringStream ss;
100 ss << "Beam State: " << GetEnumAsStringBeamState(m_ui8BeamStatus & s_BeamStateBitmask) << endl
101 << "Padding: " << static_cast<KUINT16>(m_ui8BeamStatus & s_PaddingBitmask) << endl;
103 return ss.str();
106 //////////////////////////////////////////////////////////////////////////
108 void BeamStatus::Decode( KDataStream & stream )
110 if( stream.GetBufferSize() < BEAM_STATUS_SIZE )throw KException( __FUNCTION__, NOT_ENOUGH_DATA_IN_BUFFER );
112 stream >> m_ui8BeamStatus;
115 //////////////////////////////////////////////////////////////////////////
117 KDataStream BeamStatus::Encode() const
119 KDataStream stream;
121 BeamStatus::Encode( stream );
123 return stream;
126 //////////////////////////////////////////////////////////////////////////
128 void BeamStatus::Encode( KDataStream & stream ) const
130 stream << m_ui8BeamStatus;
133 //////////////////////////////////////////////////////////////////////////
135 KBOOL BeamStatus::operator == ( const BeamStatus & Value ) const
137 if( m_ui8BeamStatus != Value.m_ui8BeamStatus ) return false;
138 return true;
141 //////////////////////////////////////////////////////////////////////////
143 KBOOL BeamStatus::operator != ( const BeamStatus & Value ) const
145 return !( *this == Value );
148 //////////////////////////////////////////////////////////////////////////
150 #endif