fix: cmake install and possible conflicting options
[KDIS.git] / src / DataTypes / UnderwaterAcousticEmitterSystem.cpp
blob0735d08722ee46b9160c0a17f6520014e1377ddf
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 "KDIS/DataTypes/UnderwaterAcousticEmitterSystem.hpp"
32 //////////////////////////////////////////////////////////////////////////
34 using namespace std;
35 using namespace KDIS;
36 using namespace DATA_TYPE;
38 //////////////////////////////////////////////////////////////////////////
39 // Public:
40 //////////////////////////////////////////////////////////////////////////
42 UnderwaterAcousticEmitterSystem::UnderwaterAcousticEmitterSystem()
43 : m_ui8EmitterSystemDataLength(UNDERWATER_ACOUSTIC_EMITTER_SYSTEM_SIZE / 4),
44 m_ui8NumBeams(0),
45 m_ui16Padding1(0) {}
47 //////////////////////////////////////////////////////////////////////////
49 UnderwaterAcousticEmitterSystem::UnderwaterAcousticEmitterSystem(
50 KDataStream& stream) {
51 Decode(stream);
54 //////////////////////////////////////////////////////////////////////////
56 UnderwaterAcousticEmitterSystem::~UnderwaterAcousticEmitterSystem() {
57 m_vUAEB.clear();
60 //////////////////////////////////////////////////////////////////////////
62 KUINT8 UnderwaterAcousticEmitterSystem::GetEmitterSystemDataLength() const {
63 return m_ui8EmitterSystemDataLength;
66 //////////////////////////////////////////////////////////////////////////
68 KUINT8 UnderwaterAcousticEmitterSystem::GetNumberOfBeams() const {
69 return m_ui8NumBeams;
72 //////////////////////////////////////////////////////////////////////////
74 void UnderwaterAcousticEmitterSystem::SetAcousticEmitterSystem(
75 const AcousticEmitterSystem& AES) {
76 m_AES = AES;
79 //////////////////////////////////////////////////////////////////////////
81 const AcousticEmitterSystem&
82 UnderwaterAcousticEmitterSystem::GetAcousticEmitterSystem() const {
83 return m_AES;
86 //////////////////////////////////////////////////////////////////////////
88 AcousticEmitterSystem&
89 UnderwaterAcousticEmitterSystem::GetAcousticEmitterSystem() {
90 return m_AES;
93 //////////////////////////////////////////////////////////////////////////
95 void UnderwaterAcousticEmitterSystem::SetLocation(const Vector& L) {
96 m_Location = L;
99 //////////////////////////////////////////////////////////////////////////
101 const Vector& UnderwaterAcousticEmitterSystem::GetLocation() const {
102 return m_Location;
105 //////////////////////////////////////////////////////////////////////////
107 Vector& UnderwaterAcousticEmitterSystem::GetLocation() { return m_Location; }
109 //////////////////////////////////////////////////////////////////////////
111 void UnderwaterAcousticEmitterSystem::AddUnderwaterAcousticEmitterBeam(
112 const UnderwaterAcousticEmitterBeam& UAEB) {
113 ++m_ui8NumBeams;
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;
124 m_vUAEB = UAEB;
125 m_ui8NumBeams = m_vUAEB.size();
126 m_ui8EmitterSystemDataLength +=
127 (m_vUAEB.size() *
128 UnderwaterAcousticEmitterBeam::UNDERWATER_ACOUSTIC_EMITTER_BEAM_SIZE) /
132 //////////////////////////////////////////////////////////////////////////
134 const vector<UnderwaterAcousticEmitterBeam>&
135 UnderwaterAcousticEmitterSystem::GetUnderwaterAcousticEmitterBeam() const {
136 return m_vUAEB;
139 //////////////////////////////////////////////////////////////////////////
141 void UnderwaterAcousticEmitterSystem::ClearUnderwaterAcousticEmitterBeams() {
142 m_ui8EmitterSystemDataLength = UNDERWATER_ACOUSTIC_EMITTER_SYSTEM_SIZE / 4;
143 m_vUAEB.clear();
144 m_ui8NumBeams = 0;
147 //////////////////////////////////////////////////////////////////////////
149 KString UnderwaterAcousticEmitterSystem::GetAsString() const {
150 KStringStream ss;
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();
165 return ss.str();
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;
177 m_vUAEB.clear();
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 {
189 KDataStream stream;
191 UnderwaterAcousticEmitterSystem::Encode(stream);
193 return 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)
214 return false;
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;
218 return true;
221 //////////////////////////////////////////////////////////////////////////
223 KBOOL UnderwaterAcousticEmitterSystem::operator!=(
224 const UnderwaterAcousticEmitterSystem& Value) const {
225 return !(*this == Value);
228 //////////////////////////////////////////////////////////////////////////