1 /*********************************************************************
2 Copyright 2013 Karl Jones
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
27 http://p.sf.net/kdis/UserGuide
28 *********************************************************************/
30 #include "KDIS/DataTypes/UnderwaterAcousticEmitterSystem.hpp"
32 //////////////////////////////////////////////////////////////////////////
36 using namespace DATA_TYPE
;
38 //////////////////////////////////////////////////////////////////////////
40 //////////////////////////////////////////////////////////////////////////
42 UnderwaterAcousticEmitterSystem::UnderwaterAcousticEmitterSystem()
43 : m_ui8EmitterSystemDataLength(UNDERWATER_ACOUSTIC_EMITTER_SYSTEM_SIZE
/ 4),
47 //////////////////////////////////////////////////////////////////////////
49 UnderwaterAcousticEmitterSystem::UnderwaterAcousticEmitterSystem(
50 KDataStream
& stream
) {
54 //////////////////////////////////////////////////////////////////////////
56 UnderwaterAcousticEmitterSystem::~UnderwaterAcousticEmitterSystem() {
60 //////////////////////////////////////////////////////////////////////////
62 KUINT8
UnderwaterAcousticEmitterSystem::GetEmitterSystemDataLength() const {
63 return m_ui8EmitterSystemDataLength
;
66 //////////////////////////////////////////////////////////////////////////
68 KUINT8
UnderwaterAcousticEmitterSystem::GetNumberOfBeams() const {
72 //////////////////////////////////////////////////////////////////////////
74 void UnderwaterAcousticEmitterSystem::SetAcousticEmitterSystem(
75 const AcousticEmitterSystem
& AES
) {
79 //////////////////////////////////////////////////////////////////////////
81 const AcousticEmitterSystem
&
82 UnderwaterAcousticEmitterSystem::GetAcousticEmitterSystem() const {
86 //////////////////////////////////////////////////////////////////////////
88 AcousticEmitterSystem
&
89 UnderwaterAcousticEmitterSystem::GetAcousticEmitterSystem() {
93 //////////////////////////////////////////////////////////////////////////
95 void UnderwaterAcousticEmitterSystem::SetLocation(const Vector
& L
) {
99 //////////////////////////////////////////////////////////////////////////
101 const Vector
& UnderwaterAcousticEmitterSystem::GetLocation() const {
105 //////////////////////////////////////////////////////////////////////////
107 Vector
& UnderwaterAcousticEmitterSystem::GetLocation() { return m_Location
; }
109 //////////////////////////////////////////////////////////////////////////
111 void UnderwaterAcousticEmitterSystem::AddUnderwaterAcousticEmitterBeam(
112 const UnderwaterAcousticEmitterBeam
& UAEB
) {
114 m_vUAEB
.push_back(UAEB
);
115 m_ui8EmitterSystemDataLength
+=
116 UnderwaterAcousticEmitterBeam::UNDERWATER_ACOUSTIC_EMITTER_BEAM_SIZE
/ 4;
119 //////////////////////////////////////////////////////////////////////////
121 void UnderwaterAcousticEmitterSystem::SetUnderwaterAcousticEmitterBeams(
122 const vector
<UnderwaterAcousticEmitterBeam
>& UAEB
) {
123 m_ui8EmitterSystemDataLength
= UNDERWATER_ACOUSTIC_EMITTER_SYSTEM_SIZE
/ 4;
125 m_ui8NumBeams
= m_vUAEB
.size();
126 m_ui8EmitterSystemDataLength
+=
128 UnderwaterAcousticEmitterBeam::UNDERWATER_ACOUSTIC_EMITTER_BEAM_SIZE
) /
132 //////////////////////////////////////////////////////////////////////////
134 const vector
<UnderwaterAcousticEmitterBeam
>&
135 UnderwaterAcousticEmitterSystem::GetUnderwaterAcousticEmitterBeam() const {
139 //////////////////////////////////////////////////////////////////////////
141 void UnderwaterAcousticEmitterSystem::ClearUnderwaterAcousticEmitterBeams() {
142 m_ui8EmitterSystemDataLength
= UNDERWATER_ACOUSTIC_EMITTER_SYSTEM_SIZE
/ 4;
147 //////////////////////////////////////////////////////////////////////////
149 KString
UnderwaterAcousticEmitterSystem::GetAsString() const {
152 ss
<< "Underwater Acoustic Emitter System:"
153 << "\n\tData Length: " << (KUINT16
)m_ui8EmitterSystemDataLength
154 << "\n\tNumber Of Beams: " << (KUINT16
)m_ui8NumBeams
155 << m_AES
.GetAsString()
156 << "\n\tLocation: " << m_Location
.GetAsString();
158 vector
<UnderwaterAcousticEmitterBeam
>::const_iterator citr
= m_vUAEB
.begin();
159 vector
<UnderwaterAcousticEmitterBeam
>::const_iterator citrEnd
= m_vUAEB
.end();
161 for (; citr
!= citrEnd
; ++citr
) {
162 ss
<< citr
->GetAsString();
168 //////////////////////////////////////////////////////////////////////////
170 void UnderwaterAcousticEmitterSystem::Decode(KDataStream
& stream
) {
171 if (stream
.GetBufferSize() < UNDERWATER_ACOUSTIC_EMITTER_SYSTEM_SIZE
)
172 throw KException(__FUNCTION__
, NOT_ENOUGH_DATA_IN_BUFFER
);
174 stream
>> m_ui8EmitterSystemDataLength
>> m_ui8NumBeams
>> m_ui16Padding1
>>
175 KDIS_STREAM m_AES
>> KDIS_STREAM m_Location
;
179 for (KUINT8 i
= 0; i
< m_ui8NumBeams
; ++i
) {
180 UnderwaterAcousticEmitterBeam UAEB
;
181 stream
>> KDIS_STREAM UAEB
;
182 m_vUAEB
.push_back(UAEB
);
186 //////////////////////////////////////////////////////////////////////////
188 KDataStream
UnderwaterAcousticEmitterSystem::Encode() const {
191 UnderwaterAcousticEmitterSystem::Encode(stream
);
196 //////////////////////////////////////////////////////////////////////////
198 void UnderwaterAcousticEmitterSystem::Encode(KDataStream
& stream
) const {
199 stream
<< m_ui8EmitterSystemDataLength
<< m_ui8NumBeams
<< m_ui16Padding1
200 << KDIS_STREAM m_AES
<< KDIS_STREAM m_Location
;
202 vector
<UnderwaterAcousticEmitterBeam
>::const_iterator citr
= m_vUAEB
.begin();
203 vector
<UnderwaterAcousticEmitterBeam
>::const_iterator citrEnd
= m_vUAEB
.end();
204 for (; citr
!= citrEnd
; ++citr
) {
205 stream
<< KDIS_STREAM
* citr
;
209 //////////////////////////////////////////////////////////////////////////
211 KBOOL
UnderwaterAcousticEmitterSystem::operator==(
212 const UnderwaterAcousticEmitterSystem
& Value
) const {
213 if (m_ui8EmitterSystemDataLength
!= Value
.m_ui8EmitterSystemDataLength
)
215 if (m_ui8NumBeams
!= Value
.m_ui8NumBeams
) return false;
216 if (m_AES
!= Value
.m_AES
) return false;
217 if (m_Location
!= Value
.m_Location
) return false;
221 //////////////////////////////////////////////////////////////////////////
223 KBOOL
UnderwaterAcousticEmitterSystem::operator!=(
224 const UnderwaterAcousticEmitterSystem
& Value
) const {
225 return !(*this == Value
);
228 //////////////////////////////////////////////////////////////////////////