Remove old changelog
[KDIS.git] / src / DataTypes / EntityMarking.cpp
blob0d55df1fec85a5288b162decb669b1d03045f912
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/EntityMarking.hpp"
32 using namespace KDIS;
33 using namespace DATA_TYPE;
34 using namespace ENUMS;
36 //////////////////////////////////////////////////////////////////////////
37 // Public:
38 //////////////////////////////////////////////////////////////////////////
40 EntityMarking::EntityMarking() : m_ui8EntityMarkingCharacterSet(0) {
41 memset(m_sEntityMarkingString, 0x00, sizeof(m_sEntityMarkingString));
44 //////////////////////////////////////////////////////////////////////////
46 EntityMarking::EntityMarking(KDataStream& stream) { Decode(stream); }
48 //////////////////////////////////////////////////////////////////////////
50 EntityMarking::EntityMarking(EntityMarkingCharacterSet MarkingCharSet,
51 const KCHAR8* MarkingText, KUINT16 TextSize)
52 : m_ui8EntityMarkingCharacterSet(MarkingCharSet) {
53 if (TextSize > 11) throw KException(__FUNCTION__, STRING_PDU_SIZE_TOO_BIG);
55 memset(m_sEntityMarkingString, 0x00, sizeof(m_sEntityMarkingString));
56 SetEntityMarkingString(MarkingText, TextSize);
59 //////////////////////////////////////////////////////////////////////////
61 EntityMarking::EntityMarking(const EntityMarkingCharacterSet MarkingCharSet,
62 const KString& MarkingText)
63 : m_ui8EntityMarkingCharacterSet(MarkingCharSet) {
64 if (MarkingText.size() > 11)
65 throw KException(__FUNCTION__, STRING_PDU_SIZE_TOO_BIG);
67 memset(m_sEntityMarkingString, 0x00, sizeof(m_sEntityMarkingString));
68 SetEntityMarkingString(MarkingText);
71 //////////////////////////////////////////////////////////////////////////
73 EntityMarking::~EntityMarking() {}
75 //////////////////////////////////////////////////////////////////////////
77 void EntityMarking::SetEntityMarkingCharacterSet(
78 EntityMarkingCharacterSet EMCS) {
79 m_ui8EntityMarkingCharacterSet = EMCS;
82 //////////////////////////////////////////////////////////////////////////
84 EntityMarkingCharacterSet EntityMarking::GetEntityMarkingCharacterSet() const {
85 return (EntityMarkingCharacterSet)m_ui8EntityMarkingCharacterSet;
88 //////////////////////////////////////////////////////////////////////////
90 void EntityMarking::SetEntityMarkingString(const KINT8* EMS,
91 KUINT16 StringSize) {
92 if (StringSize > 11) throw KException(__FUNCTION__, STRING_PDU_SIZE_TOO_BIG);
94 memcpy(m_sEntityMarkingString, EMS, StringSize);
95 m_sEntityMarkingString[StringSize] = 0x0; // Null terminate the string.
98 //////////////////////////////////////////////////////////////////////////
100 void EntityMarking::SetEntityMarkingString(const KString& EMS) {
101 if (EMS.size() > 11) throw KException(__FUNCTION__, STRING_PDU_SIZE_TOO_BIG);
103 memcpy(m_sEntityMarkingString, EMS.c_str(), EMS.size());
104 m_sEntityMarkingString[EMS.size()] = 0x0; // Null terminate the string.
107 //////////////////////////////////////////////////////////////////////////
109 KString EntityMarking::GetEntityMarkingString() const {
110 return m_sEntityMarkingString;
113 //////////////////////////////////////////////////////////////////////////
115 KString EntityMarking::GetAsString() const {
116 KStringStream ss;
118 ss << "Entity Marking:"
119 << "\n\tMaring Char Set: "
120 << GetEnumAsStringEntityMarkingCharacterSet(m_ui8EntityMarkingCharacterSet)
121 << "\n\tMarking String: " << GetEntityMarkingString() << "\n";
123 return ss.str();
126 //////////////////////////////////////////////////////////////////////////
128 void EntityMarking::Decode(KDataStream& stream) {
129 if (stream.GetBufferSize() < ENTITY_MARKING_SIZE)
130 throw KException(__FUNCTION__, NOT_ENOUGH_DATA_IN_BUFFER);
132 stream >> m_ui8EntityMarkingCharacterSet;
134 for (KUINT16 i = 0; i < 11; ++i) {
135 stream >> m_sEntityMarkingString[i];
139 //////////////////////////////////////////////////////////////////////////
141 KDataStream EntityMarking::Encode() const {
142 KDataStream stream;
144 EntityMarking::Encode(stream);
146 return stream;
149 //////////////////////////////////////////////////////////////////////////
151 void EntityMarking::Encode(KDataStream& stream) const {
152 stream << m_ui8EntityMarkingCharacterSet;
154 for (KUINT16 i = 0; i < 11; ++i) {
155 stream << m_sEntityMarkingString[i];
159 //////////////////////////////////////////////////////////////////////////
161 KBOOL EntityMarking::operator==(const EntityMarking& Value) const {
162 if (m_ui8EntityMarkingCharacterSet != Value.m_ui8EntityMarkingCharacterSet)
163 return false;
164 if (memcmp(m_sEntityMarkingString, Value.m_sEntityMarkingString, 11) != 0)
165 return false;
166 return true;
169 //////////////////////////////////////////////////////////////////////////
171 KBOOL EntityMarking::operator!=(const EntityMarking& Value) const {
172 return !(*this == Value);
175 //////////////////////////////////////////////////////////////////////////